Forum Discussion

AD_SNOW's avatar
AD_SNOW
Icon for Helper I rankHelper I
2 years ago
Solved

Find the first latest date and second latest date based on quarter selection dynamically

Team,

I have a date (which doesn't have continues dates) and quarter fields in my table (mentioned below). My quarter will go as slicer/filter and I want to find the first latest date and the second latest date based on my quarter slicer selection.

 

Date (DD/MM/YY)QuarterFlagComment
02/05/2424-Q21When I selected 24-Q2
18/04/2424-Q22When I selected 24-Q2
11/04/2424-Q2  
31/03/2424-Q11When I selected 24-Q1
29/03/2424-Q12When I selected 24-Q1
26/03/2424-Q1  
25/03/2424-Q1  
21/03/2424-Q1  
19/03/2424-Q1  
14/03/2424-Q1  
07/03/2424-Q1  
29/02/2424-Q1  
15/02/2424-Q1  
31/12/2323-Q41When I selected 23-Q4
14/12/2323-Q42When I selected 23-Q4

 

Tomorrow when data gets updated and a new date gets added (as mentioned below), my latest and second latest date flag should automatically update

Date (DD/MM/YY)QuarterFlagComment
10/05/2424-Q21New date added and the flag should show this as latest date When I selected 24-Q2
02/05/2424-Q22Automatically this should be my second latest date When I selected 24-Q2
18/04/2424-Q2  
11/04/2424-Q2  
31/03/2424-Q11When I selected 24-Q1
29/03/2424-Q12When I selected 24-Q1
26/03/2424-Q1  
25/03/2424-Q1  
21/03/2424-Q1  
19/03/2424-Q1  
14/03/2424-Q1  
07/03/2424-Q1  
29/02/2424-Q1  
15/02/2424-Q1  
31/12/2323-Q41When I selected 23-Q4
14/12/2323-Q42When I selected 23-Q4


Can someone please help me with this requirement?

 

Thanks!

  • Hi AD_SNOW 
    To get the desired result you can apply an index of every date according to the quarter from PQ . 

    The guide of how to get this is here :

    https://radacad.com/create-row-number-for-each-group-in-power-bi-using-power-query

    (Row Number By Group)

    I also attached a pbix ,  you can follow my steps

    From the moment that you have an index this is easy, you can create a simple dax measure for the flag :

    Flag = if(max('Table'[Index]) in {1,2}, MAX('Table'[Index]), " " )

     

    as I mentioned Pbix is attached 🙂

    If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

3 Replies

  • Hi AD_SNOW 
    To get the desired result you can apply an index of every date according to the quarter from PQ . 

    The guide of how to get this is here :

    https://radacad.com/create-row-number-for-each-group-in-power-bi-using-power-query

    (Row Number By Group)

    I also attached a pbix ,  you can follow my steps

    From the moment that you have an index this is easy, you can create a simple dax measure for the flag :

    Flag = if(max('Table'[Index]) in {1,2}, MAX('Table'[Index]), " " )

     

    as I mentioned Pbix is attached 🙂

    If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

  • KeyurPatel14's avatar
    KeyurPatel14
    Icon for Responsive Resident rankResponsive Resident
    Hello AD_SNOW ,
    Hope you are doing well.

    Could you please try the below measure:
    (Please know that, I have considered the QTR from the same table, if you have a date dimension table, kindly make required change in the measure)

    Max QTR Date =
    VAR maxdate =
    CALCULATE(
        MAX('Table (2)'[Date (DD/MM/YY)]),
        ALLEXCEPT('Table (2)','Table (2)'[Quarter])
    )
    VAR curdate =
    SELECTEDVALUE('Table (2)'[Date (DD/MM/YY)])
    VAR secondmaxdate =
    CALCULATE(
        MAX('Table (2)'[Date (DD/MM/YY)]),
        ALLEXCEPT('Table (2)','Table (2)'[Quarter]),
        'Table (2)'[Date (DD/MM/YY)] < maxdate
    )
    RETURN
    IF(
        maxdate = curdate,
        1,
        IF(
            curdate = secondmaxdate,
            2,
            0
        )
    )

    If this solution helps, then kindly give it a kudos and mark it as a solution.