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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Oros
Resolver III
Resolver III

Top Customers

Hello,

 

What would be the correct measure to show the Top 10 customer over a period of time?  Thanks. 

 

The resulting ranking is not based on the grand total but based on the total sales for a given month (or column period). 

 

In the example below, if there are 500 customers, the measure will show only 16 customers that fall into the TOP 10 customers for the given period which is January to May (on a month-to-month basis)

 

Oros_0-1718592265145.png

 

 

1 ACCEPTED SOLUTION

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1718681379915.png

 

 

Sales top 3 v3: =
VAR _t =
    ADDCOLUMNS (
        SUMMARIZE (
            ALLSELECTED ( sales ),
            customer[customer],
            'calendar'[MOnth-Year sort],
            'calendar'[Month-Year]
        ),
        "@result",
            CALCULATE (
                SUM ( sales[sales] ),
                KEEPFILTERS (
                    WINDOW (
                        1,
                        ABS,
                        3,
                        ABS,
                        CALCULATETABLE (
                            SUMMARIZE (
                                sales,
                                customer[customer],
                                'calendar'[MOnth-Year sort],
                                'calendar'[Month-Year]
                            ),
                            REMOVEFILTERS ( customer[customer] )
                        ),
                        ORDERBY ( CALCULATE ( SUM ( sales[sales] ) ), DESC )
                    )
                )
            )
    )
VAR _list =
    SUMMARIZE ( FILTER ( _t, [@result] <> BLANK () ), customer[customer] )
RETURN
    CALCULATE ( SUM ( sales[sales] ), KEEPFILTERS ( customer[customer] IN _list ) )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

6 REPLIES 6
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

In my sample, I tried to achieve top 3, and I hope you can reauthor the measure in your sample.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1718593479596.png

 

Jihwan_Kim_1-1718595137660.png

 

Sales: = 
SUM( sales[sales])

 

WINDOW function (DAX) - DAX | Microsoft Learn

 

Sales top 3: = 
VAR _selectedperiod =
    ALLSELECTED ( 'calendar'[MOnth-Year sort] )
VAR _t =
    ADDCOLUMNS (
        CALCULATETABLE (
            SUMMARIZE (
                ALL ( sales ),
                customer[customer],
                'calendar'[MOnth-Year sort],
                'calendar'[Month-Year]
            ),
            'calendar'[MOnth-Year sort] IN _selectedperiod
        ),
        "@sales", [Sales:]
    )
VAR _group =
    GROUPBY (
        _t,
        customer[customer],
        "@allsales", SUMX ( CURRENTGROUP (), [@sales] )
    )
VAR _toplist =
    SUMMARIZE (
        WINDOW ( 1, ABS, 3, ABS, _group, ORDERBY ( [@allsales], DESC ) ),
        customer[customer]
    )
RETURN
    CALCULATE (
        SUM ( sales[sales] ),
        KEEPFILTERS ( customer[customer] IN _toplist )
    )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Hi @Jihwan_Kim,

 

Thank you very much for your quick reply and for taking the time to send a pbix file.  I think that you are very close to the intended result.

 

One thing that I noticed is that the 2 tables do not show the top 3 per month.

(we do NOT need the top 3 by grand total)

Oros_0-1718633587934.png

 

 (we need to show all the top 3 customers in a given month.  we do NOT need show the customers who have never been in the top 3 in a given month.  the ones highlighted in red have never been in the top 3 in any of the given months). 

 

All customers in yellow have been in the top 3 in a given month.  Thanks again.

Oros_1-1718633687320.png

 

Hi,

Thank you for your message, and please check the below picture and the attached pbix file whether it suits your requirement.

 

Jihwan_Kim_0-1718643460720.png

 

 

Sales top 3 v2: =
CALCULATE (
    SUM ( sales[sales] ),
    KEEPFILTERS (
        WINDOW (
            1,
            ABS,
            3,
            ABS,
            CALCULATETABLE (
                SUMMARIZE (
                    sales,
                    customer[customer],
                    'calendar'[MOnth-Year sort],
                    'calendar'[Month-Year]
                ),
                REMOVEFILTERS ( customer[customer] )
            ),
            ORDERBY ( CALCULATE ( SUM ( sales[sales] ) ), DESC )
        )
    )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Hi @Jihwan_Kim,

 

I think that you actually nailed it! How do I show the rest of the numbers like this? I would  like to show the non-highlighted numbers, together with the yellow highlighted numbers.  Thanks again.

Oros_0-1718670911250.png

 

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1718681379915.png

 

 

Sales top 3 v3: =
VAR _t =
    ADDCOLUMNS (
        SUMMARIZE (
            ALLSELECTED ( sales ),
            customer[customer],
            'calendar'[MOnth-Year sort],
            'calendar'[Month-Year]
        ),
        "@result",
            CALCULATE (
                SUM ( sales[sales] ),
                KEEPFILTERS (
                    WINDOW (
                        1,
                        ABS,
                        3,
                        ABS,
                        CALCULATETABLE (
                            SUMMARIZE (
                                sales,
                                customer[customer],
                                'calendar'[MOnth-Year sort],
                                'calendar'[Month-Year]
                            ),
                            REMOVEFILTERS ( customer[customer] )
                        ),
                        ORDERBY ( CALCULATE ( SUM ( sales[sales] ) ), DESC )
                    )
                )
            )
    )
VAR _list =
    SUMMARIZE ( FILTER ( _t, [@result] <> BLANK () ), customer[customer] )
RETURN
    CALCULATE ( SUM ( sales[sales] ), KEEPFILTERS ( customer[customer] IN _list ) )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Hi @Jihwan_Kim ,

 

You are an absolute Superhero!!!  It works!  Thanks!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.