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])   Month Date(Measures) Jan 10/1/2024 Feb 20/2/2024 March 11/3/2024 April 10/4/2024 May ...
  • Sergii24's avatar
    2 years ago

    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!