Forum Discussion
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) )
return
IF(ranking <= 'Ranking Option'[Ranking Option Value], [Total Sales])
2 Replies
- AnonymousNot applicable
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 resultPlease 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 ForumBest Regards,
Gao
Community Support TeamIf 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
- Korekar27Helper I
Hi I tried the dax but now the same total is coming for Product and Region for Top and Bottom.