cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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:

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:

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])
)

8 REPLIES 8
Anonymous
Not applicable

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

Helper I

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:

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

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

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])
)

Helper I

@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.

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])
)

Helper I

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

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))

Helper I

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 :

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - August 2024

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

#### Fabric Community Update - August 2024

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

Top Solution Authors
Top Kudoed Authors