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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
db1Intermtn
Helper I
Helper I

Rank and Rank Increment/Decrement from selected week vs previous week

I have a table visual with branch, client and revenue information. The revenue is coming from a measure which is affected by the week selector slicer. 

rank question.png

I need to show Rank for selected week and rank increment/decrement from selected week's rank vs previous week from selected week. In snapshot, Rank # and Rank are the requirements.

I tried to create rank with AllSelected function but it is always affected by week slicer and I cannot get previous week rank to compare and put Rank increment/decrement. DAX I tried for Rank

Ranking  = 
RANKX(
            ALLSELECTED(V_TopClients),
            CALCULATE(SUM(V_TopClients[Revenue])
            )
        )

I have v_TopClients that has weekly revenue information linking to dimCalendar, Date tables.

5 REPLIES 5

 
@amitchandak 

I have calculated this week and previous week values with measures.

 

This Week = CALCULATE ( SUM ( V_TopClients[GrossProfit] ), ALLSELECTED ( DimCalendar[WeekCaption] ) )
Previous Week = CALCULATE ( SUM ( v_TopClients[GrossProfit] ), ALLSELECTED ( 'DimCalendar' ), DATEADD('Date'[Date],-7,DAY))

 

I have also calculated the Rank for this week with Dax:


Ranking This Week = RANKX( ALLSELECTED(V_TopClients), CALCULATE(SUM(V_TopClients[GrossProfit]) ) )

 

Now to show Rank increment/decrement based on the rank, I need previous week's rank. I am unable to get the rank for previous week. If I can get that, I was going to use the difference of this week's rank and previous week's rank to see the position change of the clients 

@db1Intermtn , share data from week table or week and year column 

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

@amitchandak 

 

Please find the sample data here:  https://1drv.ms/u/s!Ave_-9o8DQVEgRq42F7E2tvw1s9_?e=0CRLM4

I have uploaded for 2 weeks for top clients data and 7 weeks for sample calendar table I have.

 

top clients sample.png

 

My requirement is to show rank increase/decrease/constant for the clients on the list based on selected week vs previous week rank.

Hi @db1Intermtn 

 

write your measures like this:

this week =
VAR _maxWeekData =
    CALCULATE ( MAX ( TopClients[CalendarWeekKey] ), ALL ( TopClients ) )
RETURN
    CALCULATE (
        SUM ( TopClients[GrossProfit] ),
        FILTER ( ALL ( DimCalendar ), DimCalendar[CalendarWeekKey] = _maxWeekData )
    )

 

previous week =
VAR _maxWeekData =
    CALCULATE ( MAX ( TopClients[CalendarWeekKey] ), ALL ( TopClients ) )
VAR _previousWeek =
    CALCULATE (
        MAX ( TopClients[CalendarWeekKey] ),
        FILTER ( ALL ( TopClients ), TopClients[CalendarWeekKey] < _maxWeekData )
    )
RETURN
    CALCULATE (
        SUM ( TopClients[GrossProfit] ),
        FILTER ( ALL ( DimCalendar ), DimCalendar[CalendarWeekKey] = _previousWeek )
    )

 

Ranking This Week = RANKX( ALL(TopClients), [this week] )

 

Ranking previous Week = RANKX( ALL(TopClients), [previous week] )

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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