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
gclements
Helper II
Helper II

Rank by Date with Values

Hi,

 

I am trying to get a rank by date, starting with the most recent date, and only for dates that have values.

 

Example below.  In the example I have a number of date, some of them have quantites.  For those that do have a quantity I would like to rank the date in descending order with the most recent date being rank 1.

 

I do not know whether this should be a measure or a calculated column, but I do know that the values will change based on the filters that are applied, such as the customer.

 

Any help is much appreciated.

 

DateQuantityRank
01/01/2020  
02/01/2020  
03/01/2020106
04/01/2020  
05/01/20205005
06/01/2020  
07/01/2020  
08/01/2020  
09/01/202034
10/01/2020  
11/01/2020  
12/01/2020553
13/01/2020432
14/01/20201011
15/01/2020  
16/01/2020  
1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Here is one measure expression to try.  Change DateRank to the actual name of your table.

 

Rank if Qty =
VAR vThisRank =
    RANKX (
        FILTER (
            ALLSELECTED (
                DateRank[Date],
                DateRank[Quantity]
            ),
            DateRank[Quantity] > 0
        ),
        CALCULATE (
            MAX ( DateRank[Date] )
        ),
        ,
        DESC
    )
RETURN
    IF (
        SUM ( DateRank[Quantity] ) > 0,
        vThisRank,
        BLANK ()
    )

 

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
Microsoft Employee

Here is one measure expression to try.  Change DateRank to the actual name of your table.

 

Rank if Qty =
VAR vThisRank =
    RANKX (
        FILTER (
            ALLSELECTED (
                DateRank[Date],
                DateRank[Quantity]
            ),
            DateRank[Quantity] > 0
        ),
        CALCULATE (
            MAX ( DateRank[Date] )
        ),
        ,
        DESC
    )
RETURN
    IF (
        SUM ( DateRank[Quantity] ) > 0,
        vThisRank,
        BLANK ()
    )

 

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Fantastic.  That did the trick, thank you very much!

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!

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.