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

Creating Ranking by Week Measure on top of Virtual Tables

Hello,

 

My dashboard tracks volume collections daily. I've been able to use RANKX to create a daily ranking measure without an issue. What I would like to do now is give the current selected week a ranking in comparison with all historic weeks.

I've been able to create this ranking in a table as follows:

 

*temp = 
VAR table1 = SUMMARIZECOLUMNS(
            ORACLE_DATE_DIMENSION[week_end],
            FILTER(
                ORACLE_DATE_DIMENSION, 
                ORACLE_DATE_DIMENSION[WEEK_END]<=[pm_Selected_Period_Week_Ending]
            ),
            "Claim Volume",
            SUM(CLAIM_VOLUMES_DAILY[CLAIM_VOLUME_ADJUST])
    )

VAR table_new = 

ADDCOLUMNS(
    SUMMARIZE(
        table1,
        ORACLE_DATE_DIMENSION[WEEK_END],
        [Claim Volume]
    ),
    "Rank1", RANKX(table1,[Claim Volume],,DESC)
)

return
table_new

 

The top 5 from that table looks like this:

WEEK_ENDClaim VolumeRank1
13/12/2020 0:00419715963
6/12/2020 0:00404838484
4/10/2020 0:00377702135
12/01/2020 0:00429800211
22/12/2019 0:00425345652

 

Now I'd like to create a measure that references these virtual tables but returns the "Rank1" value based on which "WEEK_END" has been selected. I have tried to use the above variables and the following expression, but DAX does not seem to recognize 'table_new' as a proper variable:

 

*Week collection rank = 
VAR table1 = SUMMARIZECOLUMNS(
            ORACLE_DATE_DIMENSION[week_end],
            FILTER(
                ORACLE_DATE_DIMENSION, 
                ORACLE_DATE_DIMENSION[WEEK_END]<=[pm_Selected_Period_Week_Ending]
            ),
            "Claim Volume",
            SUM(CLAIM_VOLUMES_DAILY[CLAIM_VOLUME_ADJUST])
    )

VAR table_new = 
CALCULATE(
ADDCOLUMNS(
    SUMMARIZE(
        table1,
        ORACLE_DATE_DIMENSION[WEEK_END],
        [Claim Volume]
    ),
    "Rank1", RANKX(table1,[Claim Volume],,DESC)
))
return
maxx(table_new,[Rank1])

 

That code returns the error "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value." The "table_new" gets the red squiggly line, as does "Rank1".

 

Am I correct that only one virtual table can come through as a variable when used in a measure?

If so, how can I complete this calculation with one virtual table variable (or without variables)?

Sincerely,

Nicolas

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

Hi @nicolas23498324 ,

 

You could create a weeknum column.

Please check the formulas below.

 

weeknum = WEEKNUM('Table'[date],1)

Measure = CALCULATE(SUM('Table'[value]),ALLEXCEPT('Table','Table'[weeknum]))

Measure 2 = RANKX(ALLSELECTED('Table'[weeknum]),[Measure],,DESC,Dense)

 

2.PNG

3.PNG

 

Best Regards,

Jay

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

View solution in original post

3 REPLIES 3
v-jayw-msft
Community Support
Community Support

Hi @nicolas23498324 ,

 

You could create a weeknum column.

Please check the formulas below.

 

weeknum = WEEKNUM('Table'[date],1)

Measure = CALCULATE(SUM('Table'[value]),ALLEXCEPT('Table','Table'[weeknum]))

Measure 2 = RANKX(ALLSELECTED('Table'[weeknum]),[Measure],,DESC,Dense)

 

2.PNG

3.PNG

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
amitchandak
Super User
Super User

@nicolas23498324 , for rank, refer sub category rank

For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://youtu.be/DZb_6j6WuZ0

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi Amitchandak,

 

Thanks for the link. Using that approach I have successfully created a table with a ranking per week. However, I cannot figure out how to use that logic to display a measure that shows the ranking of the current week.

I understand that my attempt below fails because it removes the other weeks which it is ranking against. I guess what I want is a lookup function to return the ranking (e.g. 11) based on the elected date matched against WEEK_END. Can you suggest how I would do that?

 

*Simple Rank = 
CALCULATE(
    RANKX(
        ALL(ORACLE_DATE_DIMENSION[WEEK_END]),
        [Claim_Volume_STD],
    ),
    FILTER(
        ORACLE_DATE_DIMENSION,
        ORACLE_DATE_DIMENSION[WEEK_END]=[pm_Selected_Period_Week_Ending]
    )
)

 

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!

November Carousel

Fabric Community Update - November 2024

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

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.