Forum Discussion
Top N Filter doesn't work (with examples)
Hi Anonymous
You might consider providing your dummy pbix that would be folpful for us to investigate it further.
You can upload it to the onedrive for business and share the link here. please don't forget to disclose the expected results and remove the confidential info.
- Anonymous6 years agoNot applicable
I have created a proxy of a data table similar to the one I use (although with much less categories). My idea is to create a dashboard page in which I can filter by Top Shops: 5-10-20-50 based on the shops that have had AuM 4Q/20. I would like all the graphics to be filtered by said top N shops.
I think the problem is that i dont know how to create new measures to filter by top N shops by AuM ( DESC), in each graph.
Thanks everyone again¡¡.- PaulDBrown6 years agoCommunity Champion
Anonymous
I think I understand what you are trying to achieve: filter all visuals on the page by using one report page filter, right?
If so, you need to include a filter statement (or reference statement to the "TopN" selection) in all the measures in each visual. Otherwise the visuals will not be filtered by the global filter; only the visuals which include the "Shop" Dimension as a filter context will get filtered; all others will not.
In the following example, I've created a meaure to rank Items.
First, the model itself:
I want to see only the actuals and target for the top 3 items dimension.
As you can see, if a visual does not contain the Item dimension, the rank returned is "1" for all the other dimensions ("Channel" and "REF Dimension"). These visuals will therefore not be filtered by a page filter referencing a "TopN" Items; you need to specify the Filter context in the measures used.
In my case I have created measures as follows:To filter each dimension by its top 3 items (so the result would respect the top 3 items per each dimension), I use the following RankX measure:
RankX actuals by item = RANKX(ALL('Item Dim'), [Sum of Actuals],,DESC,Dense)Which Gives me this:
If, however,I need the top 3 Items for all dimensions (Ie the top 3 of all), I would use this measure:
RankX actuals by item (ALL dimensions) = CALCULATE([RankX actuals by item], ALL('Channel Dim'[Channel]), ALL('Ref Dim'[REF]))Which gives me this:
You can then use either of these ranks in the filter expression of measures. For Overall 3 Top Items:
Actuals Filtered by RANK Top 3 Items = CALCULATE([Sum of Actuals], FILTER('Item Dim', [RankX actuals by item (ALL dimensions)] <=3))Target Filtered by RANK Top 3 Items = CALCULATE([Sum of Target], FILTER('Item Dim', [RankX actuals by item (ALL dimensions)] <=3))Check the results:
If you look at the visuals which do not have the Items Dimension as a filter context, the rank returned for all rows is "1". The global filter would not work. You get around this by using measures which include the relevant filter context for the dimension you wish to filter by, if that makes sense (see my sample measures). When you include these measures with other dimensions, you will get the correct results (in the example, it's the columns and values in the tables/matrix with green backround, where you get the result for the top 3 overall Items and how much the contribute to the Channel or Ref Dimensions).
In your case, since you want it to be dymanic, you need to substitute the "<=3" in the filter expression in the measures with the SELECTEDVALUE expression for the TopN slicer value.
I hope that makes sense!
- Anonymous6 years agoNot applicable
Thank you very much for the full explanation, but i dont know what i'm doing wrong, i'm gonna share a powerBI proxy and put the link here to see if someone can help me because I've already tried everything.