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
wek9294
Frequent Visitor

Applying rank based on narrowed date

Hello, I'm trying to get my table to show the correct ranking based on a narrowed date field. All of the data is from one table.

 

My data has these columns:

Lane: abc - def

Cost

Date column: using the formula 

If(Datediff('table'[Date],TODAY(),WEEK)=13, "Yes","no")

 

Lane based on date column: using the formula

If('table'[Date column] = "Yes", 'table'[Lane], BLANK())

 

Narrowed Cost: using the formula

If(Datediff('table'[Date],TODAY(),WEEK)=13, 'table'[Cost], blank())

 

I'm trying to get the rank for the "Lane based on date column" using either the "Cost" or "Narrowed Cost" column.  Basically I want it to look at lanes that appeared 13 weeks ago, sum the costs, then apply a rank to those summed costs.

1 ACCEPTED SOLUTION

Hi @wek9294 ,

I created a sample pbix file(see attachment) base on your provided data, please check whether that is what you want.

1. Create a Date table(Note: Do not create any relationship between Date table and your fact table)

2. Create the below measures

 

Measure = 
VAR _seldate =
    SELECTEDVALUE ( 'Date'[Date] )
VAR _selweek =
    WEEKNUM ( _seldate )
RETURN
    CALCULATE (
        SUM ( 'Table'[Cost] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Lane] = MAX ( 'Table'[Lane] )
                && 'Table'[Week #] < _selweek
        )
    )
New cost = SUMX(VALUES('Table'[Lane]),[Measure])
Rank = 
IF (
    ISBLANK ( [New cost] ),
    BLANK (),
    RANKX ( ALLSELECTED ( 'Table' ), [New cost],, DESC, DENSE )
)

 

Applying rank based on narrowed date.JPG

Best Regards

Community Support Team _ Rena
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

3 REPLIES 3
amitchandak
Super User
Super User

@wek9294 ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

For Rank Refer these links
https://www.youtube.com/watch?v=wDS_Vi4r9I4
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns

Does this help? Here's what my raw data looks like. Note it doesn't have a "Week #" column but I added it so it's easier to know how I'm narrowing the data.

 

data 1.PNG

 

Here's what I need to get. For the report, say current date is 1/5/2020, meaning we're in week 2.

data 2.PNG

It's only adding together the values from the previous week. Note that the dates in the report will consistantly change so it can't focus on a specific week number, but instead has to look at one week prior to current week.

 

So when it's 1/12/20 and we're in week 3, I need to get

Capture.PNG

Hi @wek9294 ,

I created a sample pbix file(see attachment) base on your provided data, please check whether that is what you want.

1. Create a Date table(Note: Do not create any relationship between Date table and your fact table)

2. Create the below measures

 

Measure = 
VAR _seldate =
    SELECTEDVALUE ( 'Date'[Date] )
VAR _selweek =
    WEEKNUM ( _seldate )
RETURN
    CALCULATE (
        SUM ( 'Table'[Cost] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Lane] = MAX ( 'Table'[Lane] )
                && 'Table'[Week #] < _selweek
        )
    )
New cost = SUMX(VALUES('Table'[Lane]),[Measure])
Rank = 
IF (
    ISBLANK ( [New cost] ),
    BLANK (),
    RANKX ( ALLSELECTED ( 'Table' ), [New cost],, DESC, DENSE )
)

 

Applying rank based on narrowed date.JPG

Best Regards

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

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.