Cumulative Percent of Total - jasper-reports

Drug Item Count Total Cost Cost/Item % Total Cost Cumulative % Total Cost
Humalog 10 250 $25.00 6.7% 6.7%
Novolog 5 100 $20.00 2.7% 9.4%
Apidra 20 600 $30.00 16.1% 25.5%
Velosulin 10 800 $80.00 21.5% 47.0%
Lantus 50 1200 $24.00 32.3% 79.3%
Levemir 35 770 $22.00 20.7% 100.0%
I've got a detail band in iReport that successfully calculates cost per item and percent of total cost -- see mock-up above. For percent of total cost, I take $F{cost}/$V{sum_all_costs}. I'm having a little trouble with cumulative percent of total cost, though. I can get a variable that shows cumulative sum:
Name: RUNNING_SUM
Calculation: Sum
Reset type: Report
Increment type: None
Variable Expression: $F{cost}
Evaluation Time: Now <-- when the variable is used in the detail band
Any thoughts on how I can take this cumulative sum and get cumulative percentage?

Showing the running total is simple (as you demonstrated in the question). The problem with a running percentage is that you need to know the total first. As you point out, conceptually you need to evaluate the denominator later. But there's no way to specify that.
When I did this in the past I did it like this: Treat your entire current report as a subreport. The only change needed in the report is to add a parameter called $P{GrandTotal}. Then create a brand new report that re-uses the same query. It calculates the GrandTotal and passes it to the subreport. The master report doesn't really need any display elements at all. Now that the subreport has the total as a parameter you can do your running percentage as $F{RUNNING_SUM} / $P{GrandTotal}.
Note: The main report doesn't really need to run exactly the same query. It will probably make sense to use a modified query which calculates the total in the database. As long as it calculates the total somehow you're all set.

Related

Want to SUM all values for a specific date within column NOT sum all values in that column

I want to create a graph which shows the total capacity for each week relative to remaining availability across a series of specific dates. Just now when I attempt this in Power Bi it calculates this correctly for one of the values (remaining availability) but generates a value much higher than expected by manual calculation for the total capacity - instead showing the total for the entire column rather than for each specific date.
Why is Power Bi doing this and how can I solve it?
So far, I have tried generating the graph like this:
(https://i.stack.imgur.com/GV3vk.png)
and as you can see the capacity values are incredibly high they should be 25 days.
The total availability values are correct (ranging from 0 to 5.5 days).
When I create matrices to see the sum breakdown they are correct but it only appears to be that when combined together one of the values changes to the value for the whole column.
If anyone could help me with this issue that would be great! Thanks!

Using RANK function in Tableau on a Combined column. However, display individual columns as well

I am using RANK function in Tableau and I am displaying the Rank of calculated measure (Eg: 1 to 50)
The calculated Measure I have is Total Amount for Combined Periods.
When there is no Period displayed on the dashboard, the Total Amount is the sum of both periods and this is exactly what I want. I am good in this case.
However, When I want to display the Period in the Rows, the Total Amount changes to "Total Amount for Period 1 and Total Amount for Period 2".
How can I add a different axis to show Individual Periods as well as Rank of Total Amount for Combined Period?
I guess this might come down to Dual axis in Tableau and I believe this is not available yet and users are voting for this in Ideas.

Calculate the Average of multiple Averages

I need to calculate the average of multiple averages within Crystal Reports with specific criteria. My report averages scores for multiple courses by a developer. I need to get the average value of the averages, based on the number of courses for that developer:
Course 1 10 responses Course 1 Average 42.86
Course 2 12 responses Course 2 Average 39.36
How do I create a formula that give me the correct Average ((42.86 + 39.36)/2) of those two courses for that developer?
Try a Running Total for that field, where the Type of Summary is set to "Average". Specify that the total should reset every time it reaches a new Developer group.
Sometimes Crystal won't let you summarize a summary. If it gives you guff, you can achieve the same effect with Shared Variables. Simply add each average in turn to the shared variable, then divide by a distinct count of averages. The final Formula field would look something like:
Shared NumberVar sum;
Shared NumberVar count;
sum/count

Different Total Types in Tableau

I am trying to use Tableau's row total function but am running into a challenge. In the same widget I have Rows 1 - 4 with Numbers. Row 5 is a percentage.
What I would like to do is have Rows 1 - 4 use a Sum Total and Row 5 use an Average total.
Any suggestions on how I can do this?
Thanks,
I don't believe you can use different total metrics on the same worksheet.
What you can do is to create 2 different worsheets, and bring them side by side on a dashboard. Then use the proper Total metric in each.
But beware on calculation average of percentages, because they might be twisted. Usually weighted average is required to accurately express the "average" of a percentage.
What you can do is to actually calculate the percentage (use a calculated field) via the division of two metrics. That way, when you do Totals you will actually a valid value for the "average" of the percentage.
As an exercise, suppose you have sales (in $) in first row, and # of clients in row 2. Now I create a calculated field called ticket, that is
SUM(sales) / sum([# of clients])
That way I can add that to a third row, and for each column I'll have the right number of ticket, and if I add a Row Grand Total, I'll get the actual average ticket value (that is total sales / total # clients), because Tableau will sum all sales, sum all # clients and them perform the calculation (the division)

Crystal report loop

I have a running total and would like to stop it when a condition is matched.
Eg: I have STOCK qty 100pcs; qty is accumulated from Purchase Order Receiving transactions as below:
No. Qty Accumulate
1. 20 20
2. 30 50
3. 10 60
4. 40 100
5. 20 120
The running total should stop at no. 4, because it has reached the STOCK qty 100.
How can this be done?
I'm not sure I understand perfectly what you would like to achieve.
The running total cannot "stop". The running total evaluates by the rules set by you at the time you create the running total. If I remember well you have four options.
evaluate for each record
on change of a field
change of a group
formula
If we assume that you wanted to reset the running total after every 100 then you need to evaluate for each record (1).
For reset you have again four options:
never
on change of a field
change of a group
formula
Here you could write a formula (4) to check for the amount and reset every time when the counter reaches 100.