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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
yellow43
Helper I
Helper I

Rank with different conditions

Hello,

Hope you can help me.

I have a table and I would like to rank each row grouped by country and with 2 conditions. The conditions are as follows: 

  1. same country, different products, 1st condition: max qty.
  2. same country, different products, 1st condition: equal qty, 2nd condition: best sales amount.

Different dates may reflect different ranking.

 

The final result should be like this:

2023-02-27_17h50_39.png

Can you please help me?

Thanks in advance.

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

It is for creating a measure.

Jihwan_Kim_0-1677523870511.png

 

Jihwan_Kim_1-1677524091344.png

 

Rank measure: =
IF (
    HASONEVALUE ( Country[Country] ),
    CALCULATE (
        COUNTROWS ( Data ),
        WINDOW (
            1,
            ABS,
            0,
            REL,
            SUMMARIZE (
                ALL ( Data ),
                Country[Country],
                'Product'[Product],
                Data[Qty],
                Data[Sales Amount]
            ),
            ORDERBY ( Data[Qty], DESC, Data[Sales Amount], DESC ),
            KEEP,
            PARTITIONBY ( Country[Country] )
        )
    )
)

 

 

 

 


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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

It is for creating a measure.

Jihwan_Kim_0-1677523870511.png

 

Jihwan_Kim_1-1677524091344.png

 

Rank measure: =
IF (
    HASONEVALUE ( Country[Country] ),
    CALCULATE (
        COUNTROWS ( Data ),
        WINDOW (
            1,
            ABS,
            0,
            REL,
            SUMMARIZE (
                ALL ( Data ),
                Country[Country],
                'Product'[Product],
                Data[Qty],
                Data[Sales Amount]
            ),
            ORDERBY ( Data[Qty], DESC, Data[Sales Amount], DESC ),
            KEEP,
            PARTITIONBY ( Country[Country] )
        )
    )
)

 

 

 

 


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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hello @Jihwan_Kim ,

Measure is not working when I select my table.

I only have a single table, should it worl the same way?

Rank measure: =
IF (
    HASONEVALUE ( 'Data'[Country] ),
    CALCULATE (
        COUNTROWS ( 'Data' ),
        WINDOW (
            1,
            ABS,
            0,
            REL,
            SUMMARIZE (
                ALL ( 'Data' ),
                'Data'[Country],
                'Data'[Product],
                'Data'[Qty],
                'Data'[Sales Amount]
            ),
            ORDERBY ( Data[Qty], DESC, Data[Sales Amount], DESC ),
            KEEP,
            PARTITIONBY ( 'Data'[Country] )
        )
    )
)

Thank you!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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