Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

DATEADD based on max date

Hi folks,

 

I need to calculate the past 12 months based on the max date. Please, any idea?

 

I try dateadd and it is not working.

 

MAX_sent_payment = max('All Expenses'[Sent for Payment Date])
 
So in my example, if the max date= March-2024, I would like March-2023
Thank you,
 
Clara

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous ,

     

    Dateadd is a table function and cannot be directly useful for metric values. You can see the results returned by the dateadd function by creating a calculated table.

    You can try below formula:

    M_ = 
    CALCULATE (
        SUM ( 'Table 2'[value] ),
        DATESBETWEEN (
            'Table 2'[Date],
            MAX ( 'Table 2'[Date] ) - 365,
            MAX ( 'Table 2'[Date] )
        )
    )
    

     

    Best Regards,
    Adamk Kong

     

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

     

4 Replies

  • Anonymous try the below
    Past_12_Months_Start_Date = DATEADD(MAX('All Expenses'[Sent for Payment Date]), -12, MONTH)

    Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

    • Anonymous's avatar
      Anonymous
      Not applicable

      Yeah, that was my first approach. However, it did not work.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    Dateadd is a table function and cannot be directly useful for metric values. You can see the results returned by the dateadd function by creating a calculated table.

    You can try below formula:

    M_ = 
    CALCULATE (
        SUM ( 'Table 2'[value] ),
        DATESBETWEEN (
            'Table 2'[Date],
            MAX ( 'Table 2'[Date] ) - 365,
            MAX ( 'Table 2'[Date] )
        )
    )
    

     

    Best Regards,
    Adamk Kong

     

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