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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Koushikrish
Helper I
Helper I

DAX TOP N Measure on a Matrix Issue

Hello,

 

I have a requirement to display TOP 10 States on a Volume measure across a matrix visual. I have used the TOP N DAX Measure to achieve this : 

CALCULATE([Volume], TOPN(10, ALL(dimGeography[State_Code]), [Volume], DESC), VALUES(dimGeography[State_Code]))

Now if I use this measure on a matrix with just the State field on the Columns it works fine by displaying the TOP 10 states:

Koushikrish_0-1655999271456.png

 

But if I were to include some field on the rows of the matrix as well, its doesn't display the true TOP 10 states but TOP 10 for each item on the row. The bigger problem is that the Total appears only for the True TOP 10 states and not others:

 

Koushikrish_1-1655999426478.png

 

I think this is correct because when you include a field for the row, it considers the row context and pulls TOP 10 for that row. And the Totals are showing up only on the actual true TOP 10 states and not others. But is there a way to tweak the measure or visual to just display the True TOP 10 states only when including a row field as well? I am guessing that it would involve eliminating the row context on the measure.

 

I have also tried using a variation using RANKX to acheive this TOP 10 measure but its the same result. 

 

CALCULATE([Volume], FILTER(VALUES(dimGeography[State_Code]),IF(RANKX(ALL(dimGeography[State_Code]),[Volume],,DESC)<=10,[Net Revenue], BLANK())))

 

Would appreciate any help on this. Please let me know if you need more information!

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Koushikrish glad it worked!

To also remove the filter from Brand, this below might work (I've not tested this)

 

    CALCULATE(
        [Volume],
        TOPN(10,
            ALL(dimGeography[State_Code], dimGeography[RegionName]),
            CALCULATE([Volume], ALL('dimBrand'[BrandName]))
            DESC
        ),
        VALUES(dimGeography[State_Code])
    )

 

 

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

@Koushikrish , how should the visual look when you have Region added? Could you post the desired output, please.

Hello @Anonymous. These are the top 10 states. My desired output is to retain these Top 10 states only across columns even if I include anything on the rows.

Top 10 states:

Koushikrish_2-1656004166006.png

This is how I need it when I include Region Name on the columns : 

 

Koushikrish_3-1656004429195.png

 

 

But right now it shows this way when I include Region Name, its displaying the Top 10 states for each Region.

Koushikrish_4-1656004473272.png

Hope that info was sufficient. Else please let me know.

Anonymous
Not applicable

@Koushikrish I tried with some sample data but couldn't reproduce the first image in your firdt post.

I think that perhaps that when the Region field is added, you need the measure remove the filters from the Region Field. I think this will do it:

 

 

    CALCULATE(
        [Volume],
        TOPN(10,
            ALL(dimGeography[State_Code], dimGeography[RegionName]),
            [Volume],
            DESC
        ),
        VALUES(dimGeography[State_Code])
    )

 

 

@Anonymous : This worked great, thank you! I have another question though. Consider I have to include another column from another table on the Row (instead of Region Name). Is there a way to get rid of the filter without explicity specifiying the field name? 
For example, I tried to use another column called Brand Family on the row but it won't work as filter is removed only on the Region Name. I also tried this but didn't work as it looks like arguments for ALL function must be from same table. 

Koushikrish_0-1656007435427.png

 




Anonymous
Not applicable

@Koushikrish glad it worked!

To also remove the filter from Brand, this below might work (I've not tested this)

 

    CALCULATE(
        [Volume],
        TOPN(10,
            ALL(dimGeography[State_Code], dimGeography[RegionName]),
            CALCULATE([Volume], ALL('dimBrand'[BrandName]))
            DESC
        ),
        VALUES(dimGeography[State_Code])
    )

 

 

@Anonymous : that worked great as well. Got the result as I desired for exactly! Thanks a lot for your help on this!! 😊

amitchandak
Super User
Super User

@Koushikrish , try if this can help

measure =
var _tab = TOPN(10, ALL(dimGeography[State_Code]), [Volume], DESC)
return
CALCULATE([Volume], FILTER(VALUES(dimGeography[State_Code]),dimGeography[State_Code] in _tab))

Hi @amitchandak , thanks for the response. This doesn't seem to fix the issue though. It doesn't appear to show just top 10 but all states and mapped to their corresponding region : 

Koushikrish_0-1656003863800.png

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.