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
RMDNA
Solution Sage
Solution Sage

Rankx issue (I checked a lot of the others already)

Hey all, I already checked a lot of the solved "rankx" questions, but I didn't see anything that dealt with something as potentially simple as mine. Hopefully that'll make it easy to fix.

 

In a [Sales] table, I have [product units sold] out of [total sold], giving me a [% of total], which all looks correct. However, my rankx:

 

Sales Units Rank = rankx(all(Sales), Sales[% Sales Units])

gives weird values sometimes (see picture). In the end, my running total is:

 

Sales Unit Running Total = 
CALCULATE (
    SUM ( Sales[% Sales Units] ),
    ALL ( Sales ),
    Sales[Sales Units Rank] <= EARLIER (Sales[Sales Units Rank] )
)

Any tips?

 

1.PNG

4 REPLIES 4
v-yuta-msft
Community Support
Community Support

Hi RMDNA,

 

Based on your description, there’re three original columns [Sales Units], [Sales Units Total] and [% Sales Units] in your table, right?

 

To calculate running total which can meet your requirement, you can modify DAX formula like below:

Sales Unit Running Total =

CALCULATE (

    SUM ( Sales[% Sales Units] ),

    ALL ( Sales ),

    Sales[Sales Units Rank] <= EARLIER (Sales[Sales Units Rank] ),

    Sales[Sales Units] = EARLIER(Sales[Sales Units Rank]),

    Sales[Sales Unit Total] =  EARLIER(Sales[Sales Unit Total])

)

 

Regards,

Jimmy Tao

@v-yuta-msft,

 

'Sales Units' comes directly from the table, while 'Sales Unit Total' and '% Sales Units' are either calculated columns or measures (I've tried both).

 

When I try any of the running total examples, I get the following:

 

"A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expression. This is not allowed."

Zubair_Muhammad
Community Champion
Community Champion

@RMDNA

 

Try converting these to MEASURE...perhaps

 

Sales Units Rank =
RANKX ( ALLSELECTED ( Sales ), CALCULATE ( SUM ( Sales[% Sales Units] ) ) )
Sales Unit Running Total =
VAR myrank = [Sales Units Rank]
RETURN
    CALCULATE (
        SUM ( Sales[% Sales Units] ),
        ALLSELECTED ( Sales ),
        [Sales Units Rank] <= myrank
    )

 


Regards
Zubair

Please try my custom visuals

@Zubair_Muhammad,

 

Using your rank code as a measure [SUR] gives the following, which will still throw off the running total. It looks better, but something is still off.

 

b.PNG

 

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.