Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
IM TRYING TO USE THIS FORMULA TO CALCULATE MY CUMULATIVE TOTAL BUT FOR THE VALUES WHERE IT IS ZERO IT IS RESETTING AND BRINGING THE TOTAL VALUE WHICH IS WRONG WHAT SHOULD I DO?
Hi @samgamer3000 ,
Sample data
You can ttry this mesure
Running total =
CALCULATE(
SUMX(
FILTER(
ALLSELECTED('Table'),
'Table'[Name] <= MAX('Table'[Name])
),
[ExcessStock2]
)
)
Fianl output
In the above example, the name column is used as a sequential column for explicit ordering, if you don't have explicitly ordered columns in your data, you'll need to create them first and then use them to calculate.
Best regards,
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi it gives me this issue. Is there any alternative to calcualte running total if you data set is long?
Hi,
Share the download link of the PBI file. Show the expected result there.
The reason why it is showing total value when your [ExpressStock2] is 0 is
in your orderby parameter you have put [ExpressStock2] desc this is the sort order which it uses to perform the running sum, Ideally in descending order 0 comes after all positive numbers, so if I assume you only have positive numbers then 0 value would be in the last record before total. and (Last but one value) + 0 = (Last but one value) ~ 665400
Just put a descending sort order on your Expressstock2 measure in your table visual
you will clearly understand what is happening.
and also correct the formula with the correct index column.
Need a Power BI Consultation? Hire me on Upwork
Connect on LinkedIn
|
Hi @samgamer3000, try this code, and if you encounter any issues, let me know.
RUNNINGTOTALCUM =
VAR PreviousTotal =
CALCULATE(
MAX([ExcessStock2]),
FILTER(
ALLSELECTED(Dim_old_Code[OLD_CODE]),
Dim_old_Code[OLD_CODE] < MAX(Dim_old_Code[OLD_CODE])
)
)
RETURN
IF(
[ExcessStock2] = 0,
PreviousTotal,
PreviousTotal + [ExcessStock2]
)
Did I answer your question? If so, please mark my post as the solution!
Your Kudos are much appreciated! Proud to be a Resolver III !
The MAX function only accepts a column reference as the argument number 1. It is giving me this errors.
give this a try, and if you encounter any issues, let me know.
RUNNINGTOTALCUM =
VAR PreviousRunningTotal =
CALCULATE(
SUM([ExcessStock2]),
FILTER(
ALLSELECTED(Dim_old_Code[OLD_CODE]),
Dim_old_Code[OLD_CODE] <= MAX(Dim_old_Code[OLD_CODE])
)
)
RETURN
IF(
[ExcessStock2] = 0,
PreviousRunningTotal - [ExcessStock2],
PreviousRunningTotal
)
Did I answer your question? If so, please mark my post as the solution!
Your Kudos are much appreciated! Proud to be a Resolver III !
But the problem is my excesstock2 is a measure so when I try to add in the previous running total part is shows error but in second part it is accepting.
| User | Count |
|---|---|
| 57 | |
| 44 | |
| 32 | |
| 16 | |
| 14 |
| User | Count |
|---|---|
| 84 | |
| 68 | |
| 38 | |
| 27 | |
| 25 |