Skip to main content
cancel
Showing results for 
Search instead 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

Reply
thisiskl
Frequent Visitor

Top N / Rank for a specific month and return the last 12 month value for those Top N

Hi folks, 

 

I need to build a line chart where I need to 1. find the top 10 brands (legend) of the brand share (Y axis) for the current month. 2. Return the last 12 months (X axis) brand share for those top 10 brands identified in step 1. 

 

(Don't worry about the last 12 months, I can use filter to mannually select the 12 months)

 

I have no clue what function I should use. Rank or Related or others?

 

For now, I'm able to build the chart using top N as a filter for the legend. However this approach returned the top 10 brands based on the average brand share for the last 12 months, not the current month's brand share. 

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @thisiskl ,

 

Here I create a sample to show you how to achieve your goal. If you want to get dynamic Top N, you can create a what if parameter for slicer.

My Data model:

RicoZhou_0-1675320341639.png

Then create a measure as below.

Top N Brand Value =
VAR _TopN =
    SELECTEDVALUE ( 'Top N'[Top N] )
VAR _SUMMARIZE =
    SUMMARIZE (
        ALL ( 'Table' ),
        [Brands],
        "CurrentMonth",
            CALCULATE (
                SUM ( 'Table'[Value] ),
                FILTER (
                    'Calendar',
                    YEAR ( [Date] ) * 100
                        + MONTH ( [Date] )
                        = YEAR ( TODAY () ) * 100
                            + MONTH ( TODAY () )
                )
            )
    )
VAR _ADDRANK =
    ADDCOLUMNS (
        _SUMMARIZE,
        "Rank", RANKX ( _SUMMARIZE, [CurrentMonth],, DESC, DENSE )
    )
VAR _RANK =
    SUMX ( FILTER ( _ADDRANK, [Brands] = MAX ( 'Table'[Brands] ) ), [Rank] )
RETURN
    CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( 'Table', _RANK <= _TopN ) )

To show last 12 months data, you can use relative data function in filter field. Result is as below.

RicoZhou_1-1675320367318.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

View solution in original post

3 REPLIES 3
thisiskl
Frequent Visitor

This solution is awesome!

It works perfect for my case. I have a few filters, so I changed TODAY() to MAX(calendar[dt]) , ALL() to ALLSELECTED(). 

v-rzhou-msft
Community Support
Community Support

Hi @thisiskl ,

 

Here I create a sample to show you how to achieve your goal. If you want to get dynamic Top N, you can create a what if parameter for slicer.

My Data model:

RicoZhou_0-1675320341639.png

Then create a measure as below.

Top N Brand Value =
VAR _TopN =
    SELECTEDVALUE ( 'Top N'[Top N] )
VAR _SUMMARIZE =
    SUMMARIZE (
        ALL ( 'Table' ),
        [Brands],
        "CurrentMonth",
            CALCULATE (
                SUM ( 'Table'[Value] ),
                FILTER (
                    'Calendar',
                    YEAR ( [Date] ) * 100
                        + MONTH ( [Date] )
                        = YEAR ( TODAY () ) * 100
                            + MONTH ( TODAY () )
                )
            )
    )
VAR _ADDRANK =
    ADDCOLUMNS (
        _SUMMARIZE,
        "Rank", RANKX ( _SUMMARIZE, [CurrentMonth],, DESC, DENSE )
    )
VAR _RANK =
    SUMX ( FILTER ( _ADDRANK, [Brands] = MAX ( 'Table'[Brands] ) ), [Rank] )
RETURN
    CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( 'Table', _RANK <= _TopN ) )

To show last 12 months data, you can use relative data function in filter field. Result is as below.

RicoZhou_1-1675320367318.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

Thank you so much @v-rzhou-msft !!!

Helpful resources

Announcements
Europe Fabric Conference

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 Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.