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
Korekar27
Helper I
Helper I

Power bi Dax

I have a scenario in Power bi where in Top 5,10,15 Product and city by sales and create a filter for top and bottom where in if I click on top I can see top 5,10,15 when I click on any of top 5,top 10,top 15 and vice versa also I can choose between product and region by a filter. I solved this scenario through a dax but when i choose top button total is coming the same and when I choose bottom the total is not showing. Please tell me what could be wrong with the following dax?
Ranking = var topproduct = RANKX(ALL(Products),[Total Sales], , DESC)
var bottomproduct= RANKX(ALL(Products),[Total Sales], , ASC)
var topcity = RANKX(ALL('India City Lat Long'),[Total Sales], , DESC)
var bottomcity= RANKX(ALL('India City Lat Long'),[Total Sales], , ASC)
var ranking= IF(CONTAINSSTRING(SELECTEDVALUE(Breakdown[Breakdown Fields]),"Products") ,IF(SELECTEDVALUE(TopBottom[Value])= "Top", topproduct,bottomproduct) ,IF(SELECTEDVALUE(TopBottom[Value])= "Top",topcity,bottomcity) )
Screenshot 2023-10-14 222014.pngreturn
IF(ranking <= 'Ranking Option'[Ranking Option Value], [Total Sales])

2 REPLIES 2
v-cgao-msft
Community Support
Community Support

Hi @Korekar27 ,

Please try like:

 

Ranking =
VAR topproduct =
    RANKX ( ALL ( Products ), [Total Sales],, DESC )
VAR bottomproduct =
    RANKX ( ALL ( Products ), [Total Sales],, ASC )
VAR topcity =
    RANKX ( ALL ( 'India City Lat Long' ), [Total Sales],, DESC )
VAR bottomcity =
    RANKX ( ALL ( 'India City Lat Long' ), [Total Sales],, ASC )
VAR ranking =
    IF (
        CONTAINSSTRING ( SELECTEDVALUE ( Breakdown[Breakdown Fields] ), "Products" ),
        IF ( SELECTEDVALUE ( TopBottom[Value] ) = "Top", topproduct, bottomproduct ),
        IF ( SELECTEDVALUE ( TopBottom[Value] ) = "Top", topcity, bottomcity )
    )
VAR result = 
    IF (
        HASONEVALUE(Products) || HASONEVALUE('India City Lat Long'),
        IF ( ranking <= 'Ranking Option'[Ranking Option Value], [Total Sales] ),
        CALCULATE([Total Sales], ALL(Products), ALL('India City Lat Long'))
    )
RETURN result

 

Please try this and see if it works for your scenario. If not, please provide more details (No private data) about your data model.
How to provide sample data in the Power BI Forum

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Hi I tried the dax but now the same total is coming for Product and Region for Top and Bottom.

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.