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
msaninfo
Helper I
Helper I

Instead Top N records, show inbetween N to N.....

I have a query in the data, Instead showing Top N records, would need to show data only for 1-5 or 5-10 or 11-5 & etc., based on Ranking..  based on selection.. Any 

 

Column Structure

Country     Measure     Time Period      Value..  

Country1    Value              Sep'21           100000

Country2    Volume            Oct'21          2000000

 

msaninfo_0-1637854136107.png

 

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

Here is one way using a slicer (you can also set it up using bookmarks and buttons if you prefer)

1) Create a table using "Enter Data" in the Home ribbon. This is the slicer for the TopN selection

topN table.PNG

 2) This is how my sample model is set up, which is relevant for the measures and visuals:

model.PNG

Then create the following measures:

 

 

Sum Sales = 
SUM(FactTable[Sales])
Rank by sales = 
RANKX(ALL('Country Table'[Country Table]), [Sum Sales],,DESC)

 

and finally the measure for the matrix

 

TopN Measure =
VAR _Table =
    SUMMARIZE ( FactTable, 'Country Table'[Country Table], 'Period Table'[Period] )
RETURN
    SWITCH (
        SELECTEDVALUE ( 'TopN'[Index] ),
        1, CALCULATE ( [Sum Sales], FILTER ( _Table, [Rank by sales] < 4 ) ),
        2,
            CALCULATE (
                [Sum Sales],
                FILTER ( _Table, [Rank by sales] > 3 && [Rank by sales] < 7 )
            ),
        3,
            CALCULATE (
                [Sum Sales],
                FILTER ( _Table, [Rank by sales] > 6 && [Rank by sales] < 10 )
            ),
        4, CALCULATE ( [Sum Sales], FILTER ( _Table, [Rank by sales] > 9 ) ),
        [Sum Sales]
    )

 

and this is what you get

TopN3.gif

 

 I've attached the sample PBIX file





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

6 REPLIES 6
v-shex-msft
Community Support
Community Support

Hi @msaninfo,

Did PaulDBrown 's suggestions help with your scenario? if that is the case, you can consider Kudo or accept his suggestions to help others who faced similar requirements.

If that also doesn't help, please share more detailed information to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
PaulDBrown
Community Champion
Community Champion

Here is one way using a slicer (you can also set it up using bookmarks and buttons if you prefer)

1) Create a table using "Enter Data" in the Home ribbon. This is the slicer for the TopN selection

topN table.PNG

 2) This is how my sample model is set up, which is relevant for the measures and visuals:

model.PNG

Then create the following measures:

 

 

Sum Sales = 
SUM(FactTable[Sales])
Rank by sales = 
RANKX(ALL('Country Table'[Country Table]), [Sum Sales],,DESC)

 

and finally the measure for the matrix

 

TopN Measure =
VAR _Table =
    SUMMARIZE ( FactTable, 'Country Table'[Country Table], 'Period Table'[Period] )
RETURN
    SWITCH (
        SELECTEDVALUE ( 'TopN'[Index] ),
        1, CALCULATE ( [Sum Sales], FILTER ( _Table, [Rank by sales] < 4 ) ),
        2,
            CALCULATE (
                [Sum Sales],
                FILTER ( _Table, [Rank by sales] > 3 && [Rank by sales] < 7 )
            ),
        3,
            CALCULATE (
                [Sum Sales],
                FILTER ( _Table, [Rank by sales] > 6 && [Rank by sales] < 10 )
            ),
        4, CALCULATE ( [Sum Sales], FILTER ( _Table, [Rank by sales] > 9 ) ),
        [Sum Sales]
    )

 

and this is what you get

TopN3.gif

 

 I've attached the sample PBIX file





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






msaninfo
Helper I
Helper I

I would need to display the list of countires and sum of sales nos. grouping by 5.... 1-5 or 6-10 & ..., based on latest time period.. The slicer option would be 1-5, 6-10, 11-15, 16-20... 

 

below the sample matrix table . The list of 5 countries should change baed on selection...

 

msaninfo_1-1637857124269.png

 

 

Is the TopN monthly? yearly?...





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






PaulDBrown
Community Champion
Community Champion

Can you please provide a larger data sample? It's hard to work on a TopN with only two rows (and you have a column for different measures, which ideally should be pivoted to create different columns for each measure)....What measure is the TopN supposed t calculate?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Below is the data fields....

msaninfo_0-1637856154133.png

 

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.