Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Dynamic Relative Date

I am trying to create a measure to show month over month with the below exceptions.   Example on February 1st, instead of showing sales comparing February 1st to January 1st.  I want to show Januar...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous,
    Perhaps you can try to use the date function to directly define the date range to calculate:

    PMTD =
    VAR _end =
        DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, DAY ( TODAY () ) )
    VAR _start =
        DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 )
    RETURN
        CALCULATE (
            SUM ( 'Table'[Qty] ),
            FILTER (
                ALLSELECTED ( 'Table' ),
                'Table'[Date] >= _start
                    && 'Table'[Date] <= _end
            )
        )

    Regards,

    Xiaoxin Sheng