Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Ramachandran
Helper III
Helper III

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

Ramachandran_0-1652701311547.png

Expected Output

Ramachandran_2-1652701790824.png

 

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

1 ACCEPTED SOLUTION

Hi @Ramachandran ,

I've fixed it for you now. Please add the highlighted bit to your code and it will work

Ranking_ =
RANKX(
Sales,
CALCULATE(SUM('Sales'[SalesAmount]), ALLEXCEPT(Sales,Sales[ProductCategory])),
,
ASC,
Dense
)

rohit_singh_0-1652734590808.png

Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 😊

View solution in original post

11 REPLIES 11
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Untitled.png

 

Running sales amount: = 
VAR currentsalesamount = [Sales Amount Measure:]
RETURN
    CALCULATE (
        [Sales Amount Measure:],
        FILTER ( ALL ( Data ), [Sales Amount Measure:] <= currentsalesamount )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Based on your input, I made changes to the measure and then, I'm getting the result is below, 

Ramachandran_0-1652714969877.png

Not showing all the row data
Running sales amount: =
VAR currentsalesamount = [SalesAmount]
RETURN
CALCULATE (
[SalesAmount],
FILTER ( ALL ( Sales ), [SalesAmount] <= currentsalesamount )
)

Hi @Ramachandran ,

On your table, create calculated column called "Sales Rank" to rank sales in ascending order

Sales Rank =
RANKX(
RunningTotal,
RunningTotal[SalesAmount],
,
ASC,
Dense)

rohit_singh_0-1652717155697.png

 

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

rohit_singh_1-1652717236211.png


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! 😊



 

Based on your inputs, I created Sales Rank and Running Sales measures.

Now, Running value is not showing correctly,

Ramachandran_0-1652720612797.png

 

Hi @Ramachandran , 

Please ensure these need to be calculated columns and not measures. 

I created Ranking is calculated column and Running Sales is a measure.

Hi @Ramachandran ,

Both need to be calculated columns 

I have created both columns in calculated columns but is not working. 
for your reference, I have attached .pbix file link.
https://drive.google.com/file/d/1QdUPg6K2-7Jzk-sfbQ012GxROXaVVgol/view?usp=sharing

 

please check

Hi @Ramachandran ,

I've fixed it for you now. Please add the highlighted bit to your code and it will work

Ranking_ =
RANKX(
Sales,
CALCULATE(SUM('Sales'[SalesAmount]), ALLEXCEPT(Sales,Sales[ProductCategory])),
,
ASC,
Dense
)

rohit_singh_0-1652734590808.png

Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 😊

Hi @Ramachandran ,

Could you please share the DAX code that you've used to create these columns?

I used the code is below,

Ranking = RANKX(
ALL('Sales'[ProductCategory]),
[SalesAmount],,
ASC,
DENSe
)

Running sales =

var _rank = 'Sales'[Ranking]
var _sum = CALCULATE( Sum('Sales'[SalesAmount]),
FILTER('Sales',
'Sales'[Ranking] <= _rank)
)

return
_sum

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.