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
Anonymous
Not applicable

Top 5 in Rows and Columns

Hi Everyone,

 

Adding one more situation in the given scenario. (I am using SQL server direct query source hence unable to add new tables in model)

 

I want to filter category first and then in the filter category I want fetch top 5 associate name and top 5 divison in that particulat category.

 

Below is the Raw data

 

CategoryAssociateDivisionSpend
BusinessA1Road234
AssetA2Services343
ElectriicalA1Home223
LabourA4Services555
BusinessA5Group4234
AssetA6Medical234
ElectriicalA7Music344
LabourA6Home2344
BusinessA9Vehicle434
AssetA6Hospital434
ElectriicalA11Class2
LabourA12Veg23434
BusinessA13Cream234
AssetA6Home2344
ElectriicalA9Vehicle434
LabourA6Hospital434

Asset

A11Class2

 

Result would be say I filtered Category using page level Filter as Asset. Therfore under asser Top5 supplier and Top 5 spend would be like below snapshot. Mine motive is to segereate the Associate name by category and under cateory which are the Top5 associate and their spend with Top5 division(In column in powerBi)

 

Capture.PNG

 

 

 

 

 

Kindly help I am struggling on this from last couple of weeks. I am new in PowerBi therefore need support from you.

 

Regards

Uphar Tandon

1 ACCEPTED SOLUTION

@Anonymous - Try replacing your ALL statements with ALLSELECTED. ALLSELECTED is kind of tricky but it might work for you. But, the issue is almost certainly your ALL statements.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

Well, seems like RANKX and TOPN are out-of-the-question: https://docs.microsoft.com/en-us/analysis-services/tabular-models/dax-formula-compatibility-in-direc...

 

So maybe this will help:

https://community.powerbi.com/t5/Quick-Measures-Gallery/To-Bleep-with-RANKX/m-p/1042520#M452


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi @Greg_Deckler 

 

Already gone throught  but still unable to create the DAX query or you can say the DAX is not given the correct output.

 

I am using below DAX but when I am applying Page level Filter (Say in Category as Asset) the result it not accurate.

 

Please find the DAX 

 

SpendTop5= 
VAR __topN = 5
VAR __associate = 
    RANKX (
        ALL ( 'Table'[Associate] ),
        CALCULATE( 
            [spend], 
            ALLEXCEPT( 'Table', 'Table'[Associate] ) ),
        ,
        DESC,
        DENSE
    ) <= __topN
VAR __division = 
    RANKX (
        ALL ( 'Table'[Division] ),
        CALCULATE( 
            [spend], 
            ALLEXCEPT( 'Table', 'Table'[Division] ) ),
        ,
        DESC,
        DENSE
    ) <= __topN
RETURN 
    IF( __division && __associate, [spend] )

 

If you could see, I am applying category filter in my dashboard therefore result is not accurate. I am looking for a DAX that can filter Category and then fetch top5 associate name and their Top5 Division.

 

Thanks

Uphar

@Anonymous - Try replacing your ALL statements with ALLSELECTED. ALLSELECTED is kind of tricky but it might work for you. But, the issue is almost certainly your ALL statements.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi @Greg_Deckler 

 

Thank you so much for your suggestion. I replaced All with All selected and now able to get the results.

 

The only change I have done here is that I am only fetching divsion from DAX Top 5 associate names are filtering out through powerbi Top N Filter option and for Category I am filtering through page level filter. 

 

But its works and giving the correct output.

 

Below Is the query which I perfromed.

 

VAR __division = 
    RANKX (
        SelectedALL ( 'Table'[Division] ),
        CALCULATE( 
            [spend], 
            ALLEXCEPT( 'Table', 'Table'[Division] ) ),
        ,
        DESC,
        DENSE
    ) <= __topN
RETURN 
    IF( __division && __associate, [spend] )

 

Really appreciate

 

Regards

Uphar Tandon

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.

Top Solution Authors