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
jeremyguzman
New Member

Ranking Customers by Gross Margin (Measure) by Month

Hello,

 

I have a list of clients and would like to be able to show their Rank in a given month for each month.

Example: Client1 ranked as our highest client (1) in January, but in February they dropped to our 3rd highest client (3). I would like to display the columns on the page as:

 

Client Name  |  Gross Margin Month to date  | Rank this month | GM Last Month | Rank Last Month | Change in Rank Up or Down arrows

 

For what it is worth, Gross Margin is a RankX modeled Measure based on various other data elements.

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

Hi @jeremyguzman ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

vtangjiemsft_0-1689128582181.png

(2) We can create a table.

Calendar = CALENDAR(DATE(2023,1,1),DATE(2023,12,31))

vtangjiemsft_1-1689128617370.png

 

(3) We can create measures.

GMLastMonth = 
var _lastdate=EOMONTH(MAX('Table'[date]),-1)
return CALCULATE([GrossMargin], FILTER(ALL('Table'),YEAR('Table'[date])= YEAR(_lastdate) && MONTH('Table'[date])=MONTH(_lastdate) && 'Table'[Client Name]=MAX('Table'[Client Name])))
GrossMarginMTD = 
CALCULATE([GrossMargin], FILTER(ALL('Table'),YEAR('Table'[date])=YEAR(MAX('Table'[date])) && MONTH('Table'[date])=MONTH(MAX('Table'[date])) && 'Table'[Client Name]=MAX('Table'[Client Name])))
RankLastMonth = RANKX(ALLSELECTED('Table'[Client Name]), [GMLastMonth], , DESC)
RankThisMonth = RANKX(ALLSELECTED('Table'[Client Name]), [GrossMarginMTD], , DESC)
ChangeInRank = [RankLastMonth] - [RankThisMonth]
Flag = IF('Table'[ChangeInRank] >0 ,2,1)

(4)Setting the Conditional Format and then the result is as follows.

vtangjiemsft_2-1689128793150.pngvtangjiemsft_3-1689128813857.pngvtangjiemsft_4-1689128822465.png

 

 

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

1 REPLY 1
v-tangjie-msft
Community Support
Community Support

Hi @jeremyguzman ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

vtangjiemsft_0-1689128582181.png

(2) We can create a table.

Calendar = CALENDAR(DATE(2023,1,1),DATE(2023,12,31))

vtangjiemsft_1-1689128617370.png

 

(3) We can create measures.

GMLastMonth = 
var _lastdate=EOMONTH(MAX('Table'[date]),-1)
return CALCULATE([GrossMargin], FILTER(ALL('Table'),YEAR('Table'[date])= YEAR(_lastdate) && MONTH('Table'[date])=MONTH(_lastdate) && 'Table'[Client Name]=MAX('Table'[Client Name])))
GrossMarginMTD = 
CALCULATE([GrossMargin], FILTER(ALL('Table'),YEAR('Table'[date])=YEAR(MAX('Table'[date])) && MONTH('Table'[date])=MONTH(MAX('Table'[date])) && 'Table'[Client Name]=MAX('Table'[Client Name])))
RankLastMonth = RANKX(ALLSELECTED('Table'[Client Name]), [GMLastMonth], , DESC)
RankThisMonth = RANKX(ALLSELECTED('Table'[Client Name]), [GrossMarginMTD], , DESC)
ChangeInRank = [RankLastMonth] - [RankThisMonth]
Flag = IF('Table'[ChangeInRank] >0 ,2,1)

(4)Setting the Conditional Format and then the result is as follows.

vtangjiemsft_2-1689128793150.pngvtangjiemsft_3-1689128813857.pngvtangjiemsft_4-1689128822465.png

 

 

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

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.