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

Previous Date

Dear , 

i have data: Month and Date(measures) like:

Date(measures)=max(table[Date])

 

MonthDate(Measures)
Jan10/1/2024
Feb20/2/2024
March11/3/2024
April10/4/2024
May 
Jun19/06/2024

 

how can i get previous date like:

 

MonthMeasures Pre
Jan01/01/2024
Feb10/1/2024
March20/2/2024
April11/3/2024
May 
Jun10/4/2024
1 ACCEPTED SOLUTION
Sergii24
Super User
Super User

Hi @Jyaulhaq, you can achieve the desired result using the following calcualtion:

Measures Pre = 
VAR _CurrentDate = SELECTEDVALUE( 'Table'[Date] )       //get the current date
VAR _GlobalMin =                                        //get the global minimum
    CALCULATE(
        MIN( 'Table'[Date] ),
        ALL( 'Table' )                                  //to remove impact of any other column from the same table
    )

VAR _PrevDate =                                         //PrevDate
    CALCULATE(
        MAX( 'Table'[Date] ),
        ALL( 'Table' ),                                 //to remove impact of any other column from the same table (such as "Month")
        'Table'[Date] < _CurrentDate
    )

RETURN 
    IF(
        _CurrentDate = _GlobalMin,                      //so the first row is selected
        DATE( YEAR( TODAY() ), 1, 1 ),                  //the date you need
        _PrevDate
    )


Here is the output:

Sergii24_0-1712235820879.png


Have a great day!

View solution in original post

1 REPLY 1
Sergii24
Super User
Super User

Hi @Jyaulhaq, you can achieve the desired result using the following calcualtion:

Measures Pre = 
VAR _CurrentDate = SELECTEDVALUE( 'Table'[Date] )       //get the current date
VAR _GlobalMin =                                        //get the global minimum
    CALCULATE(
        MIN( 'Table'[Date] ),
        ALL( 'Table' )                                  //to remove impact of any other column from the same table
    )

VAR _PrevDate =                                         //PrevDate
    CALCULATE(
        MAX( 'Table'[Date] ),
        ALL( 'Table' ),                                 //to remove impact of any other column from the same table (such as "Month")
        'Table'[Date] < _CurrentDate
    )

RETURN 
    IF(
        _CurrentDate = _GlobalMin,                      //so the first row is selected
        DATE( YEAR( TODAY() ), 1, 1 ),                  //the date you need
        _PrevDate
    )


Here is the output:

Sergii24_0-1712235820879.png


Have a great day!

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

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.