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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
sharpcm01
Frequent Visitor

RANKX by a group with a date slicer from a related table

I spent far too long on this, and I'm admittedly no expert. I need some major help using RANKX to rank net profit within each industry, based on whatever month is selected in the date slicer. I've successfully ranked the profit by group, but the slicer has no effect on the ranking. The slicer does correctly recalculate the Net Profit for the single month or multiple months selected, but the ranking only ranks the latest month. 

 

I have 3 tables with relationships:

A date table: Below is a similar model. The actual table goes on for years, dating back to 2018 up to current date.

DateKey
1/1/202201-2022
1/2/202201-2022
1/3/202201-2022
1/4/202201-2022
1/5/202201-2022
1/6/202201-2022
1/7/202201-2022
1/8/202201-2022
1/9/202201-2022
1/10/202201-2022
1/11/202201-2022
1/12/202201-2022
1/13/202201-2022
1/14/202201-2022
1/15/202201-2022
1/16/202201-2022
1/17/202201-2022
1/18/202201-2022
1/19/202201-2022
1/20/202201-2022
1/21/202201-2022
1/22/202201-2022
1/23/202201-2022
1/24/202201-2022
1/25/202201-2022
1/26/202201-2022
1/27/202201-2022

 

Our Dealer Summary, which is updated daily. Table actually holds about 250 columns of data, but the two columns that are relevant are below.

Dealer IDIndustry
1Auto
2Auto
3Auto
4Auto
5Auto
6Auto
7Furniture
8Furniture
9Furniture
10Furniture
11Furniture
12Furniture
13Furniture
14Furniture

 

And a YTD Net Profit table, provided to me monthly. The Net Profit % is a measure.

KeyDealer IDRevenueNet ProfitNet Profit %
01-20221 $           23,000 $           12,00052%
02-20221 $           25,000 $           11,00044%
03-20221 $           30,000 $           15,00050%
04-20221 $           35,000 $           17,00049%
05-20221 $           28,000 $           12,00043%
06-20221 $           40,000 $           23,00058%
07-20221 $           50,000 $           23,00046%
01-20222 $         240,000 $         100,00042%
02-20222 $         250,000 $         230,00092%
03-20222 $         230,000 $         120,00052%
04-20222 $         235,000 $         150,00064%
05-20222 $         450,000 $         250,00056%
06-20222 $         230,000 $         100,00043%
07-20222 $         310,000 $         160,000

52%

 

The Dealer ID is on the YTD Net Profit is related to the Dealer Summary Dealer ID. 

The Key on the YTD Net Profit is related to the Date Table's Key.

I've created the following calculated column. 

 
Profit Rank by Industry =
VAR ThisGroup = 'Dealer Summary'[Industry]
RETURN
    if(not(ISBLANK('YTD Net Profit'[Net Profit %])),
    RANKX(
        FILTER(
            ALLSELECTED('Dealer Summary'),
            'Dealer Summary'[Industry] = ThisGroup
        ),
        'YTD Net Profit'[Net Profit %],
        ,
        ,
        Skip
    ),BLANK())

 

The slicer uses the month from the Date column of the Date Table. How can I get the formula to use the recalculated net profit to re-rank, based on the slicer?

3 REPLIES 3
amitchandak
Super User
Super User

@sharpcm01 , create measure not a column.

 

Profit Rank by Industry =
VAR ThisGroup = Max('Dealer Summary'[Industry])
RETURN
if(not(ISBLANK('YTD Net Profit'[Net Profit %])),
RANKX(
FILTER(
ALLSELECTED('Dealer Summary'),
'Dealer Summary'[Industry] = ThisGroup
),
'YTD Net Profit'[Net Profit %],
,
,
Skip
),BLANK())

 

In case month year is part of the visual, rank will get distributed inside that one

 

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

Adding max doesn't work, and I'm left with 4 distinct values across 22,000 or so lines and 20 or so industries.

Adding max doesn't work, and I'm left with 4 distinct values across 22,000 or so lines and 20 or so industries.  

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.