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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply

Ranking Formula by Week Help Needed (pbix file link attached)

I am trying to have a conditional formatting to rank users by week in the "Welcome Center" location only and to ignore $0 or blanks. Red is the lowest amount of the week and green is the highest amount for that week with shades in between to show how they did against each other. So far, I got the location and $0 down but when I have all the weeks visible in the matrix, it ranks the dollars based on every week that is showing. 

Example:

 

ThisIsHalloween_0-1719493963237.png

 

 

To show you what I want each week to look like, if you use the slicer on the bottom of the page and select one week only, that is how the gradient should look even when all weeks are selected.

 

Example:

 

ThisIsHalloween_1-1719494055249.png

 

 

Here is the DAX that is being used for the conditional formatting:

 

 

 

ConFormWC = 

VAR SumTotal = 
SUM('Data by Week'[Total])

VAR Locations = 
IF(SELECTEDVALUE('Data by Week'[Total Rank]) = "No",0,"Welcome Center")

VAR Rk = 
    RANK(
        DENSE,
        ALLEXCEPT('Data by Week','Data by Week'[User ],'Data by Week'[Sorting Location],'Data by Week'[Period Title]),
       ORDERBY('Data by Week'[Sort Loc Num], ASC,'Data by Week'[Total], ASC BLANKS LAST)
    )
    RETURN
    IF(
        OR(
            SumTotal = 0,
            Locations = 0),
            BLANK(),Rk)

 

 

 

What do I need to change to make the ranking look at that week's data only?

 

 

I can't upload the pbix file to the forum (I guess I am not a high enough user yet). So here is a link to OneDrive: Anonymous.pbix 

 

Edit: it seems that the file may not be opening. It worked for me when I tested it in cognito. So, here is a google drive link instead and see if that works. If it doesn't, let me know: https://drive.google.com/file/d/1OIUk8ygcjB306IFblEtlCock4ZKx6qfw/view?usp=sharing 

 

If that one gives you any issues, here is a Box link: https://app.box.com/s/fv9d7kxdezlt5xkj52al069c9j30in2b  I am trying to maximize my chance of getting this figured out. Thanks!

1 ACCEPTED SOLUTION

lbendlin_0-1719588168189.png

Conform = 
var a = CALCULATETABLE(VALUES(Employees[User ]),REMOVEFILTERS(Employees[User ]))
var b = ADDCOLUMNS(a,"t",CALCULATE(sum('Data by Week'[Total])))
return if(max('Sorting Location'[Sorting Location])="Welcome Center",divide(sum('Data by Week'[Total])-minx(b,[t]),maxx(b,[t])-minx(b,[t])))

View solution in original post

7 REPLIES 7
lbendlin
Super User
Super User

link requires login - please check.

If the google drive gives you issues, I uploaded to Box too: https://app.box.com/s/fv9d7kxdezlt5xkj52al069c9j30in2b 

lbendlin_0-1719588168189.png

Conform = 
var a = CALCULATETABLE(VALUES(Employees[User ]),REMOVEFILTERS(Employees[User ]))
var b = ADDCOLUMNS(a,"t",CALCULATE(sum('Data by Week'[Total])))
return if(max('Sorting Location'[Sorting Location])="Welcome Center",divide(sum('Data by Week'[Total])-minx(b,[t]),maxx(b,[t])-minx(b,[t])))

That worked! Thank you so much!!!!  I really appreciate it! Now, to sit down and analyze your formula so I know how to do it for next time. 

you can use DAXFormatter to make it look nicer.

Conform =
VAR a =
    CALCULATETABLE (
        VALUES ( Employees[User ] ),
        REMOVEFILTERS ( Employees[User ] )
    )
VAR b =
    ADDCOLUMNS ( a, "t", CALCULATE ( SUM ( 'Data by Week'[Total] ) ) )
RETURN
    IF (
        MAX ( 'Sorting Location'[Sorting Location] ) = "Welcome Center",
        DIVIDE (
            SUM ( 'Data by Week'[Total] ) - MINX ( b, [t] ),
            MAXX ( b, [t] ) - MINX ( b, [t] )
        )
    )

VAR a - collects all users for the current week by removing the filter on User but keeping all other filters

VAR b - calculates the total value of each of these users

RETURN statement:  Instead of a ranking you do a sort of percentile-ing, from 0 to 1.  You do that by finding the minimum and maximum values for that week, and then scale them so the minimum is 0 and the maximum is 1.  The actual value will be in between, and can now serve as the basis for the color formatting in a consistent manner , regardless of the actual data ranges per week (and conveniently ignoring the blanks too).

Thank you for breaking it down! That is such a huge help! 

That's so weird since I tested in In Cognito and it works on my end. Let's try google drive: https://drive.google.com/file/d/1OIUk8ygcjB306IFblEtlCock4ZKx6qfw/view?usp=sharing . Let me know if that works. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.