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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
MKYZ22
New Member

Group top 20 customers

I want to show top 20 customers datails & the other customers one row as attached 

 

MKYZ22_0-1714249157442.png

 

1 ACCEPTED SOLUTION
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 described top 5 but I hope you can make it to show top 20 in your sample.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_2-1714582993188.png

 

Jihwan_Kim_3-1714583159982.png

 

 

 

 

WINDOW function (DAX) - DAX | Microsoft Learn

 

 

Top 5 and others: =
VAR _topN = 5
VAR _topNlist =
    WINDOW (
        1,
        ABS,
        _topN,
        ABS,
        ALL ( customer[customer] ),
        ORDERBY ( CALCULATE ( SUM ( sales[sales] ) ), DESC )
    )
VAR _topNsales =
    CALCULATE ( SUM ( sales[sales] ), _topNlist )
VAR _topNsaleskeepfilter =
    CALCULATE ( SUM ( sales[sales] ), KEEPFILTERS ( _topNlist ) )
VAR _allsales =
    CALCULATE ( SUM ( sales[sales] ), REMOVEFILTERS ( customer[customer] ) )
VAR _othersales = _allsales - _topNsales
RETURN
    SWITCH (
        TRUE (),
        SELECTEDVALUE ( category[category] ) = "others", IF ( NOT HASONEVALUE ( customer[customer] ), _othersales ),
        SELECTEDVALUE ( category[category] ) = "top_N", _topNsaleskeepfilter,
        _allsales
    )

 

 

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.


Go to My LinkedIn Page


View solution in original post

1 REPLY 1
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 described top 5 but I hope you can make it to show top 20 in your sample.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_2-1714582993188.png

 

Jihwan_Kim_3-1714583159982.png

 

 

 

 

WINDOW function (DAX) - DAX | Microsoft Learn

 

 

Top 5 and others: =
VAR _topN = 5
VAR _topNlist =
    WINDOW (
        1,
        ABS,
        _topN,
        ABS,
        ALL ( customer[customer] ),
        ORDERBY ( CALCULATE ( SUM ( sales[sales] ) ), DESC )
    )
VAR _topNsales =
    CALCULATE ( SUM ( sales[sales] ), _topNlist )
VAR _topNsaleskeepfilter =
    CALCULATE ( SUM ( sales[sales] ), KEEPFILTERS ( _topNlist ) )
VAR _allsales =
    CALCULATE ( SUM ( sales[sales] ), REMOVEFILTERS ( customer[customer] ) )
VAR _othersales = _allsales - _topNsales
RETURN
    SWITCH (
        TRUE (),
        SELECTEDVALUE ( category[category] ) = "others", IF ( NOT HASONEVALUE ( customer[customer] ), _othersales ),
        SELECTEDVALUE ( category[category] ) = "top_N", _topNsaleskeepfilter,
        _allsales
    )

 

 

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.


Go to My LinkedIn Page


Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.