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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Kate_Lashko
Frequent Visitor

Wrong Totals with RANKX and filters

Hello there,

I'm having trouble calculating correct subtotals. I have a visual which is filtered by multiple slicers. I have struggled with this for hours and the best I achieved is that it calculates correct totals by region but whenever I choose a random amount of values to show it outputs the totals for the whole region. Furthermore, it should switch and calculate on the basis of field parameters which are country and project id. I'm attaching a screenshot of the setup.Screenshot 2024-01-10 125041.jpg

Here's my formula:

 

Ranking Top Approved =
VAR _topCountry =
RANKX(ALL(df_countries[Country]), [Total Amount Approved], , DESC)
VAR _botCountry =
RANKX(ALL(df_countries[Country]), [Total Amount Approved], , ASC)

VAR _topProject =
RANKX(ALL(df_copy[Project ID]), [Total Amount Approved], , DESC)
VAR _botProject =
RANKX(ALL(df_copy[Project ID]), [Total Amount Approved], , ASC)

VAR _ranking = IF(CONTAINSSTRING(SELECTEDVALUE(Breakdown[Breakdown Fields]), "Country"),
IF(SELECTEDVALUE(TopBottom[Value]) = "Top", _topCountry, _botCountry),
IF(SELECTEDVALUE(TopBottom[Value]) = "Top", _topProject, _botProject)
)

VAR _total =
    SUMX(
    FILTER(
        SUMMARIZE(
        df_countries,
        df_countries[Country]),
        _ranking <= SELECTEDVALUE('Ranking Option'[Ranking Option])
        ),
        [Total Amount Approved]
)

RETURN
    SWITCH(
        TRUE(),
        ISINSCOPE(df_countries[Country]),
        IF(_ranking <= SELECTEDVALUE('Ranking Option'[Ranking Option]), [Total Amount Approved]),
        ISINSCOPE(df_copy[Project ID]),
        IF(_ranking <= SELECTEDVALUE('Ranking Option'[Ranking Option]), [Total Amount Approved]),
        _total
    )
 
I'd greatly appreciate any ideas.
1 ACCEPTED SOLUTION
v-tangjie-msft
Community Support
Community Support

Hi @Kate_Lashko ,

 

You can create a new measure and place it on the visual object.

NewTotalMeasure = SUMX(VALUES(Table[Country]), [Total]) 

vtangjiemsft_0-1704938609340.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

View solution in original post

1 REPLY 1
v-tangjie-msft
Community Support
Community Support

Hi @Kate_Lashko ,

 

You can create a new measure and place it on the visual object.

NewTotalMeasure = SUMX(VALUES(Table[Country]), [Total]) 

vtangjiemsft_0-1704938609340.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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