Crystal Reports combine sum total with percentage calculation as string - crystal-reports

I have a table of data in Crystal, using the summarise feature I can add a sum total at the bottom of each column but I'd like to add the percentage calculation in brackets next to the sum total.
For example I have,
Column A 432
Column B 191
Is there a formula I can use to show "SumColumn B (SumColumnB/SumColumnA %)"?

Managed to resolve this with the code below:
totext(sum({table1.ColumnB},{table.Site}),0)&" ("&totext(sum({table1.ColumnB},{table1.Site})/sum({table1.ColumnA},{table1.Site})*100,2)&"%)"
Using the table.Site to sum each group separately.
Resulting in following output:
191 (44.21%)

Related

Percentage of total changes on applying filter

I have a data table with three dimensions and one measure. For each row, I am trying to calculate the percentage of total (calculated by taking the sum of rows) using a calculated field.
As seen in the screenshot attached, For the column titles 'Dec-19' I want the values to be a percentage of current value / grand total (calculated at the bottom as 122,187)
Screenshot of DataTable:
So e.g. for the Column B value of 2000, the Dec-19 column should be (97/122,187) * 100 = 0.079.
I have achieved this by creating a calculated field with the formula: SUM (sales) / MAX ({EXCLUDE (Column B): Sum (sales}), where sales is the measure used in the datatable.
However, upon application of filter on column B, the percentage value changes. e.g. if I select the value 2000 in my filter for column B, I get the percentage as 100%. It seems as if the percentage is being calculated based on only the rows in the filter.
Since you haven't included any sample data, I created some sample data like this, hope this resemble yours.
Thereafter, I built a cross-tab view in tableau, somewhat like yours
If that is the scenario, use a calculated field, say CF like this, instead of yours
([Sales])/
{FIXED [Col1], DATETRUNC('month', [Col3]) : sum([Sales])}
Dragging it in the view
and thus, filtering won't affect your calculation

Pick group totals, grand totals and normal summarization in Tableau

I am trying to calculate average of 2 columns in another column in Tableau but difficult part is grand total is not getting average instead it is the sum of 3rd calculated field.
A B Calculated field
10 5 2
6 3 2
T 16 8 4 (Here I should get 2 instead it is taking sum of column)
Here I am unable to write separate formula for row totals and grand totals, Only one formula (Calculated Field) is allowed and when I am dragging on sheet it is by default aggregating to sum.
Note: I am expert in Crystal and BO but beginner in Tableau.
Update
Code used for LoD
{FIXED [Product Category]: AVG([Sales])}
Below image is what I got after implementation I have tried with 2 columns but the result is same if I use only one column (I am trying to get the average of sales)
You are almost there - the Grand Total by default does a SUM function you just have use the Total All Using --> Average option.
Output : Level wise SUM(Profit) later averaged across columns and rows. (Show Column Grand Total & Show Row Grand Total active)
Update: Answering the question below. To get the Row-wise avg (which is Cat1-vag in this case) you could just drop the measure and change it to AVG(). Since you needed in a Calculated Field you could use a Simple FIXED LOD. You can also uncheck aggregated measures from Analysis dropdown and have no Dimension in column or row like unlike what this example shows and still get three different averages. Cheers.
{FIXED [Cat1]:AVG([Profit])}
Check out this very smart work around from Joe Mako.
https://community.tableau.com/thread/112791
create a calc field like:
IF FIRST()==0 THEN
WINDOW_AVG(SUM([Sales]),0,IIF(FIRST()==0,LAST(),0))
END
duplicate your Category field
place "Category (copy)" on the level of detail
set the compute using for the calc field pill to use "Category (copy)"
The window function in the calculated field only takes into account what's in the view, and aggregate based on those number.

Sum two columns together in Tableau

In Tableau, I am trying to figure out how to sum up the percentages of two columns. I calculated the percentages using the percentages of command and used the table option, from the analysis menu. This generated the table shown below. I would like a column that sums the 4 and 5 columns together to show a total percentage of 59.76 which is 26.83+32.93 from columns 4 and 5. How would I create this calculated field?
How I generated the percentages:

Crystal Reports Division Formula Not Calculating as Desired

I am one step away from finishing up a report in Crystal 2008. I have included a snapshot of the report below. For some reason I cannot get the formula in the yellow column to calculate correctly. I am trying to divide the value of Net A for each main data source/year into the yearly Total of Net A to get the % of Data for each Main Data Source. Net A is pulling from a field in access and the total of Net A is a running total based on a current Run Date using formula ({HNT_End_To_End_Data.REPT_YYMM} = cStr(currentdate,'yyMM') in the evaluate section of the running total and the field is reset on each change of Year.
The formula in the yellow column is currently ({HNT_End_To_End_Data.Net_A}/Sum ({HNT_End_To_End_Data.Net_A}))*100 and is showing values that are like it's doing NetA divided into the grand total of Net A of all 3 years (3,727,560/108,666,439) rather than the dividing into individual year (3,727,560/34,981,163). I'm attempting to get the formula to divide each Main Data Source for each year into the yearly Net A total.
I've tried doing many different formulas and have had no luck, so would appreciate any suggestions anyone might have.
Do you have a group on year({sometable.somedate})? You need to add that group into your aggregate (sum) function:
(
{HNT_End_To_End_Data.Net_A}
/
Sum({HNT_End_To_End_Data.Net_A}, year({sometable.somedate}))
) * 100
EDIT: After reviewing the report I can see you are using a conditional formula {HNT_End_To_End_Data.REPT_YYMM} <> cStr(currentdate,'yyMM') to suppress the detail section. So SUM({HNT_End_To_End_Data.Net_A},{HNT_End_To_End_Data.SERVICE_THRU_YEAR}) is actually including the records which aren't being displayed. You have a number of ways to get around this. The simplest is probably to create a new formula for net_a:
if {HNT_End_To_End_Data.REPT_YYMM} <> cStr(currentdate,'yyMM') then
{HNT_End_To_End_Data.Net_A}
else
0;
You can then do:
(
{HNT_End_To_End_Data.Net_A}
/
Sum({#net_a}, year({sometable.somedate}))
) * 100

Calculating a weighted average for a group

I have a reports similar to the following:
I need it to look like the following:
The report is grouped by Department. I cannot figure out how to create the formula field YTD AVG to calculate and show in each group footing and then reset for the next group.
I understand the calculation for the YTD AVG, for example YTD AVG for dept1 would be:
((80*100)+(100*40)) / (100+40)
I just don't know how to get it in Crystal Reports.
Use Crystal's weighted average summary function:
Insert a summary, and select the group footer
Select the database field containing the average
Select Weighted average with
Select the field containing the number of responses
Create a formula called 'Month_Total' and place it in the details section for each row/month and suppress it {month.average} * {month.responses} In your example, this will give you the "(80*100)" and "(100*40)" portions.
Create another formula called 'Department_Avg' and place it in the department group footer section sum({#Month_Total},{month.month_name}) / sum({month.responses},{month.month_name})
The second parameter to Sum() should match whatever department-related field you're already grouping on and specifies that you want to sum only over the individual groups. This will give you your entire YTD calculation for each group/department.