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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

DAX: Ranking a measure based on a Column

Hello All,

 

I am trying to create ranking of sales by customers and customer groups.

Now these customers are been grouped as tier 1 and tier2.

 

But in visualization I am using only Customer column but not Customergroup.

 

Data looks like as below 

Mohan1029_0-1658317118725.png

Power Query:- 

 

 

 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hZQ7csMwDETvopozJkBSIOtcIZ3HZQq3vn8RfeBoyZWVyh6/pfSMhXS/T18yhUlu6aZRdf0acm7L5/L7I/xhiQe3WZgb8DwT13zwapl4EjhfC3Ad9ZqlFSti1GvxhINeLZX4oachNj5/6K1cgKdeT4Ok7fIJ8aG38KrMDXgR4qin0oijXi4ZeB71yn48I0a9OSlzo3I6juV6Ox3Hcr0d52Us18spiFHPy+m5UTkdx+l5Ox3H6Xk7zmcqdyvn+/nzUkyg4d4PR2ysiCLoWc6vgqp7UxCx864pwXVzhBqnCJfOKle2dbSlqVSypT9UabYf7nM52/q/bRtt90WjRPekb7vGERvXjSLdxo4r18iWVk7iqPspgr5UwDtjF7PzDBrT8N469I73zOMX", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, #"Begin of Week" = _t, Sales = _t, #"Customer Group" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer", type text}, {"Sales", Int64.Type}, {"Customer Group", type text}}),
    #"Changed Type with Locale" = Table.TransformColumnTypes(#"Changed Type", {{"Begin of Week", type date}}, "en-ZA"),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type with Locale", "Tier1/2", each if [Customer Group] <> "Tier2" then "Tier 1" else "Tier 2")
in
    #"Added Conditional Column"

 

 

 

 

 

 

I have created table visual as below and I have timeslicer which filters the dates and customer hierarchy slicer with customer and customergroup in it.

 

I have created ranking measure using below dax

 

 

 

 

 

Total Sales = CALCULATE(SUM('Table'[Sales]),ALLSELECTED('Table'[Begin of Week]))


Top 5 Customers  = 
    RANKX(
        ALL('Table'[Customer]),
        CALCULATE(
            'Table'[Total Sales],
            ALLEXCEPT('Table','Table'[Customer],'Table'[Customer Group])
            )
            ,,
            DESC
    )

 

 

 

 

 

 

Above measure giving me the result as below

 

Mohan1029_1-1658318302003.png

The ranking for Tier2 customers it is giving right output, but the other customers the ranking it returns as 1 only.

 

Output that I am expecting as

 

Mohan1029_0-1658318748113.png

 

Note:- In final visualization, I will not be using that Customer group. So ranking should work though i do not use that column in visual.

Expected result.

Begin of WeekCustomerTotal SalesTop 5Expected RankingRule
03-01-2022C18615105Part of Tier1 customegroup
10-01-2022C18615105Part of Tier1 customegroup
17-01-2022C18615105Part of Tier1 customegroup
24-01-2022C18615105Part of Tier1 customegroup
31-01-2022C18615105Part of Tier1 customegroup
03-01-2022C2991894Part of Tier1 customegroup
10-01-2022C2991894Part of Tier1 customegroup
17-01-2022C2991894Part of Tier1 customegroup
24-01-2022C2991894Part of Tier1 customegroup
31-01-2022C2991894Part of Tier1 customegroup
03-01-2022C51036283Part of Tier1 customegroup
10-01-2022C51036283Part of Tier1 customegroup
17-01-2022C51036283Part of Tier1 customegroup
24-01-2022C51036283Part of Tier1 customegroup
31-01-2022C51036283Part of Tier1 customegroup
03-01-2022C91078175Part of Tier2 customegroup
10-01-2022C91078175Part of Tier2 customegroup
17-01-2022C91078175Part of Tier2 customegroup
24-01-2022C91078175Part of Tier2 customegroup
31-01-2022C91078175Part of Tier2 customegroup
03-01-2022C41081262Part of Tier1 customegroup
10-01-2022C41081262Part of Tier1 customegroup
17-01-2022C41081262Part of Tier1 customegroup
24-01-2022C41081262Part of Tier1 customegroup
31-01-2022C41081262Part of Tier1 customegroup
03-01-2022C31114451Part of Tier1 customegroup
10-01-2022C31114451Part of Tier1 customegroup
17-01-2022C31114451Part of Tier1 customegroup
24-01-2022C31114451Part of Tier1 customegroup
31-01-2022C31114451Part of Tier1 customegroup
03-01-2022C71154144Part of Tier2 customegroup
10-01-2022C71154144Part of Tier2 customegroup
17-01-2022C71154144Part of Tier2 customegroup
24-01-2022C71154144Part of Tier2 customegroup
31-01-2022C71154144Part of Tier2 customegroup
03-01-2022C101160933Part of Tier2 customegroup
10-01-2022C101160933Part of Tier2 customegroup
17-01-2022C101160933Part of Tier2 customegroup
24-01-2022C101160933Part of Tier2 customegroup
31-01-2022C101160933Part of Tier2 customegroup
03-01-2022C61197522Part of Tier2 customegroup
10-01-2022C61197522Part of Tier2 customegroup
17-01-2022C61197522Part of Tier2 customegroup
24-01-2022C61197522Part of Tier2 customegroup
31-01-2022C61197522Part of Tier2 customegroup
03-01-2022C81275611Part of Tier2 customegroup
10-01-2022C81275611Part of Tier2 customegroup
17-01-2022C81275611Part of Tier2 customegroup
24-01-2022C81275611Part of Tier2 customegroup
31-01-2022C81275611Part of Tier2 customegroup

 

Anyone please suggest me.

 

Thanks,

Mohan V.

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

Hi, @Anonymous ;

Try it.

 

Total Sales = CALCULATE(SUM('Table'[Sales]),FILTER(ALLSELECTED('Table'),[Customer Group]=MAX('Table'[Customer Group])&&[Customer]=MAX('Table'[Customer])))
Top 5 Customers = 
    RANKX(
        FILTER( ALL('Table'),[Tier1/2]=MAX('Table'[Tier1/2])),
        CALCULATE(
            [Total Sales])
            
            ,,
            DESC,Dense)

 

The final show:

vyalanwumsft_0-1658739851627.png

Best Regards,
Community Support Team _ Yalan Wu
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

7 REPLIES 7
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

Try it.

 

Total Sales = CALCULATE(SUM('Table'[Sales]),FILTER(ALLSELECTED('Table'),[Customer Group]=MAX('Table'[Customer Group])&&[Customer]=MAX('Table'[Customer])))
Top 5 Customers = 
    RANKX(
        FILTER( ALL('Table'),[Tier1/2]=MAX('Table'[Tier1/2])),
        CALCULATE(
            [Total Sales])
            
            ,,
            DESC,Dense)

 

The final show:

vyalanwumsft_0-1658739851627.png

Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , You are using date in visual, and rank will distribute inside date.

 

In your, measure remove the date or use that in rank too

 

Power BI Rank Across dimension tables: https://youtu.be/X59qp5gfQoA

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak The dates should be there in the visual.

But the ranking should be done by the total sales of each customer for all dates.

 

Please find the Pbix file for your refernce.

https://1drv.ms/u/s!AmauTLNmHKexhGcs7UQE-SoJtnTZ

 

 

@Anonymous  Try if the two measures can help

 

M1= CALCULATE(SUM('Table'[Sales]),,filter(allseleced('Table'),'Table'[Customer] = max('Table'[Customer]) && 'Table'[Customer Group] =max('Table'[Customer Group] )))


Top 5 Customers =
RANKX(
ALL('Table'[Customer],'Table'[Customer Group], 'Table'[Date]),
[M1]
,,
DESC
)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak below is the expected result that i am looking for.

Please help.

Begin of WeekCustomerTotal SalesTop 5Expected RankingRule
03-01-2022C18615105Part of Tier1 customegroup
10-01-2022C18615105Part of Tier1 customegroup
17-01-2022C18615105Part of Tier1 customegroup
24-01-2022C18615105Part of Tier1 customegroup
31-01-2022C18615105Part of Tier1 customegroup
03-01-2022C2991894Part of Tier1 customegroup
10-01-2022C2991894Part of Tier1 customegroup
17-01-2022C2991894Part of Tier1 customegroup
24-01-2022C2991894Part of Tier1 customegroup
31-01-2022C2991894Part of Tier1 customegroup
03-01-2022C51036283Part of Tier1 customegroup
10-01-2022C51036283Part of Tier1 customegroup
17-01-2022C51036283Part of Tier1 customegroup
24-01-2022C51036283Part of Tier1 customegroup
31-01-2022C51036283Part of Tier1 customegroup
03-01-2022C91078175Part of Tier2 customegroup
10-01-2022C91078175Part of Tier2 customegroup
17-01-2022C91078175Part of Tier2 customegroup
24-01-2022C91078175Part of Tier2 customegroup
31-01-2022C91078175Part of Tier2 customegroup
03-01-2022C41081262Part of Tier1 customegroup
10-01-2022C41081262Part of Tier1 customegroup
17-01-2022C41081262Part of Tier1 customegroup
24-01-2022C41081262Part of Tier1 customegroup
31-01-2022C41081262Part of Tier1 customegroup
03-01-2022C31114451Part of Tier1 customegroup
10-01-2022C31114451Part of Tier1 customegroup
17-01-2022C31114451Part of Tier1 customegroup
24-01-2022C31114451Part of Tier1 customegroup
31-01-2022C31114451Part of Tier1 customegroup
03-01-2022C71154144Part of Tier2 customegroup
10-01-2022C71154144Part of Tier2 customegroup
17-01-2022C71154144Part of Tier2 customegroup
24-01-2022C71154144Part of Tier2 customegroup
31-01-2022C71154144Part of Tier2 customegroup
03-01-2022C101160933Part of Tier2 customegroup
10-01-2022C101160933Part of Tier2 customegroup
17-01-2022C101160933Part of Tier2 customegroup
24-01-2022C101160933Part of Tier2 customegroup
31-01-2022C101160933Part of Tier2 customegroup
03-01-2022C61197522Part of Tier2 customegroup
10-01-2022C61197522Part of Tier2 customegroup
17-01-2022C61197522Part of Tier2 customegroup
24-01-2022C61197522Part of Tier2 customegroup
31-01-2022C61197522Part of Tier2 customegroup
03-01-2022C81275611Part of Tier2 customegroup
10-01-2022C81275611Part of Tier2 customegroup
17-01-2022C81275611Part of Tier2 customegroup
24-01-2022C81275611Part of Tier2 customegroup
31-01-2022C81275611Part of Tier2 customegroup
Anonymous
Not applicable

Thanks for the help @amitchandak 

Please check the question as i have updated the expected result.

But it is not working as expected.

Mohan1029_0-1658327835935.png

Its returning the ranks for total sales but not as per the Customer groups.

 

If you see the dax which i tried, giving the ranking for the Tier2 groups properly, but not to the Tier1 groups.

Total Sales = CALCULATE(SUM('Table'[Sales]),ALLSELECTED('Table'[Begin of Week]))


Top 5 Customers  = 
    RANKX(
        ALL('Table'[Customer]),
        CALCULATE(
            'Table'[Total Sales],
            ALLEXCEPT('Table','Table'[Customer],'Table'[Customer Group])
            )
            ,,
            DESC
    )

 

Mohan1029_1-1658328145544.png

 

Two issues with the above query

1 - It gives the same ranks for tier1 customers - should give the ranks for these customers as per the total sales values in desc.

Mohan1029_2-1658328239711.png

 

2 - When i remove the Customergroup column from the visual. ranks are given as per the total sales, but it should break as per the customer group.

Mohan1029_3-1658328358955.png

Need your help @amitchandak 

 

Thanks,

Mohan V.

Anonymous
Not applicable

@amitchandak @Ashish_Mathur Could you please help me with this.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors