Forum Discussion

Jyaulhaq's avatar
Jyaulhaq
Frequent Visitor
2 years ago
Solved

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
  • 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:


    Have a great day!

1 Reply

  • 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:


    Have a great day!