Forum Discussion
Running value is not working as expected
Hi,
Im trying to get sales amount running value. it is working in descending order but not working in ascending order. can you please provide some suggestion?
Source Data
Expected Output
I used calculation is below
Running Value =
VAR PdtRank =
RANKX(
ALLSELECTED('Sales'[Product Category]),
[SalesAmount] ,,
ASC,
Dense
)
VAR RunningTotal =
CALCULATE(
[SalesAmount],
FILTER(
ALLSELECTED('Sales'[Product Category]),
PdtRank >= RANKX(
ALLSELECTED('Sales'[Product Category]),
[SalesAmount],,
ASC,
Dense
)
)
)
RETURN RunningTotal
I got blank value for all rows. how do I fix it?
thanks,
Ram
Hi Ramachandran ,
I've fixed it for you now. Please add the highlighted bit to your code and it will workRanking_ =RANKX(Sales,CALCULATE(SUM('Sales'[SalesAmount]), ALLEXCEPT(Sales,Sales[ProductCategory])),,ASC,Dense)Kind regards,
Rohit
Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 😊
11 Replies
- Jihwan_Kim
Super User
Hi,
Please check the below picture and the attached pbix file.
Running sales amount: = VAR currentsalesamount = [Sales Amount Measure:] RETURN CALCULATE ( [Sales Amount Measure:], FILTER ( ALL ( Data ), [Sales Amount Measure:] <= currentsalesamount ) )- Ramachandran
Helper III
Based on your input, I made changes to the measure and then, I'm getting the result is below,
Not showing all the row data
Running sales amount: =
VAR currentsalesamount = [SalesAmount]
RETURN
CALCULATE (
[SalesAmount],
FILTER ( ALL ( Sales ), [SalesAmount] <= currentsalesamount )
)- rohit_singh
Solution Sage
Hi Ramachandran ,
On your table, create calculated column called "Sales Rank" to rank sales in ascending orderSales Rank =RANKX(RunningTotal,RunningTotal[SalesAmount],,ASC,Dense)Next, create another calculated column to compute running total
Running Sales =var _rank = RunningTotal[Sales Rank]var _sum = CALCULATE(SUM(RunningTotal[SalesAmount]), FILTER(RunningTotal, RunningTotal[Sales Rank] <= _rank))return_sum
This should give you the desired output.Kind regards,
Rohit
Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 😊