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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
AD_SNOW
Helper I
Helper I

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!

1 ACCEPTED SOLUTION
Ritaf1983
Super User
Super User

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

Ritaf1983_0-1715700138914.png

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]), " " )
Ritaf1983_1-1715700333649.png

 

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.

View solution in original post

3 REPLIES 3
AD_SNOW
Helper I
Helper I

Thanks Both @Ritaf1983 @KeyurPatel14 . Both the solutions are working as expected. As @Ritaf1983 posted first, I have accepted her solution.

Thanks both again, really appreciated!!

KeyurPatel14
Responsive Resident
Responsive 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.
Ritaf1983
Super User
Super User

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

Ritaf1983_0-1715700138914.png

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]), " " )
Ritaf1983_1-1715700333649.png

 

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.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.