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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
yellow43
Helper I
Helper I

Create a new column with Rank with Multiple Columns and group by

Hi Fabric Community,

I need help with following: 

CustomercountryproductqtyAVG sales
ALEXGermanyA10 
ALEXGreeceA10 
ALEXGreeceB20 
ALEXSpainC355680,00 €
ALEXSpainB20 
ALEXSpainA272100,00 €
ALEXSpainA1420520,00 €

 

Expected Output:

CustomercountryproductqtyAVG salesRank measure:
ALEXSpainC355680,00 €3
ALEXSpainA272100,00 €1
ALEXSpainA1420520,00 €2

 

Conditions:

1. same customer, same country, different product should rank by qty (1st criteria) and then by avg_sales (2nd criteria)

2. ignore all null values and zero values in columns [qty] and [AVG sales]

 

I have already following measure:

Rank measure: =
IF (
HASONEVALUE ( 'Table'[country] ),
CALCULATE (
COUNTROWS ( 'Table' ),
WINDOW (
1,
ABS,
4,
REL,
SUMMARIZE (
ALL ( 'Table'),
'Table'[country],
'Table'[product],
'Table'[qty], 'Table'[AVG Sales]

),
ORDERBY ( 'Table'[qty], ASC, 'Table'[AVG Sales], ASC ),
DEFAULT,
PARTITIONBY ( 'Table'[country])
)
)
)

 

 

 

But is not ignoring null and zero values. 

 

Can you help me?

Thank you!

1 ACCEPTED SOLUTION
DallasBaba
Skilled Sharer
Skilled Sharer

@yellow43 to create a new column with rank based on multiple columns and group by, you can use the following DAX formula:

Rank measure = 
IF (
    HASONEVALUE ( 'Table'[country] ),
    CALCULATE (
        COUNTROWS ( 'Table' ),
        WINDOW (
            1,
            ABS,
            4,
            REL,
            SUMMARIZE (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[qty] > 0 && 'Table'[AVG sales] > 0
                ),
                'Table'[country],
                'Table'[product],
                'Table'[qty],
                'Table'[AVG sales]
            ),
            ORDERBY (
                'Table'[qty],
                ASC,
                'Table'[AVG sales],
                ASC
            ),
            DEFAULT,
            PARTITIONBY ( 'Table'[country] )
        )
    )
)

 

This formula will ignore all null and zero values in columns [qty] and [AVG sales]. It will rank the rows based on the criteria you specified: same customer, same country, different product should rank by qty (1st criteria) and then by  AVG sales (2nd criteria).

 

Please note that the formula is case-sensitive and the column names must match exactly with the ones in your table. Also, make sure to replace 'Table' with the name of your table.

 

Let me know if this works for you. @ me in replies, or I'll lose your thread!!!  
Note:
If this post is helpful, please mark it as the solution to help others find it easily. Also, if my answers contribute to a solution, show your appreciation by giving it a thumbs up
Thanks
Dallas

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @yellow43 ,

If I understand correctly, the issue is that you want to create a new column with Rank. Please try the following methods and check if they can solve your problem:

1.Create the simple table.

vjiewumsft_0-1706173995337.png

2.Create a new measure to rank. Enter the following DAX formula.

00_Rank = if(SUM('Table'[AVG sales])>0, RANKX(FILTER(ALLSELECTED('Table'),'Table'[qty]>0),CALCULATE(SUM('Table'[AVG sales])),,ASC,Dense) )

 

3.Drag the measure to the table visual.

vjiewumsft_1-1706174016150.png

4.The result is shown below.

vjiewumsft_2-1706174024256.png

 

Best Regards,

Wisdom Wu

 

 

 

 

 

DallasBaba
Skilled Sharer
Skilled Sharer

@yellow43 to create a new column with rank based on multiple columns and group by, you can use the following DAX formula:

Rank measure = 
IF (
    HASONEVALUE ( 'Table'[country] ),
    CALCULATE (
        COUNTROWS ( 'Table' ),
        WINDOW (
            1,
            ABS,
            4,
            REL,
            SUMMARIZE (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[qty] > 0 && 'Table'[AVG sales] > 0
                ),
                'Table'[country],
                'Table'[product],
                'Table'[qty],
                'Table'[AVG sales]
            ),
            ORDERBY (
                'Table'[qty],
                ASC,
                'Table'[AVG sales],
                ASC
            ),
            DEFAULT,
            PARTITIONBY ( 'Table'[country] )
        )
    )
)

 

This formula will ignore all null and zero values in columns [qty] and [AVG sales]. It will rank the rows based on the criteria you specified: same customer, same country, different product should rank by qty (1st criteria) and then by  AVG sales (2nd criteria).

 

Please note that the formula is case-sensitive and the column names must match exactly with the ones in your table. Also, make sure to replace 'Table' with the name of your table.

 

Let me know if this works for you. @ me in replies, or I'll lose your thread!!!  
Note:
If this post is helpful, please mark it as the solution to help others find it easily. Also, if my answers contribute to a solution, show your appreciation by giving it a thumbs up
Thanks
Dallas

Hello @DallasBaba , 

Big Help!

Thank you so much!

@yellow43 I am happy to know it works.  Kindly @ me with any future needs around Power BI and Fabric.

 

Please give it a kudos by clicking the Thumbs Up! It goes a long way to helping others find this solution quickly.

Thanks
Dallas

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.