Search code examples
powerbidaxvisualizationpowerbi-desktop

MoM comparison on Area Chart results in +1 day


I'm calculating the last 30 days vs the previous 30 days.

These are my measures:

Total Current 30 Days = 
CALCULATE(
    [Switch Currency],
    FILTER(
        'Calendar',
        'Calendar'[Date] >= TODAY() - 31 &&
        'Calendar'[Date] <= TODAY() - 2
    )
)

and

Total Previous 30 Days = 
CALCULATE(
    'Costs Summary Table'[Sum of measures],
    FILTER(
        'Calendar',
        'Calendar'[Date] >= TODAY() - 61 &&  -- Go back 61 days to cover a full 30-day period before the previous 30 days
        'Calendar'[Date] <= TODAY() - 32    -- Go back 32 days to end 31 days ago
    )
)

If I put the two on the Area Chart I see this:

enter image description here

  • Total Previous 30 Days: goes from the 25 of April till the 24 of May (29 days)
  • Total Current 30 Days: goes from the 25 of May till the 23 of June (29 days)

And if I check on timeanddate.com they are really 29 days:

enter image description here

But if I overlap them one results in 30 days, the other in 31 days. (note I have removed the Month from the x-axis):

enter image description here

Where am I wrong?


Solution

  • I found a solution:

    Total Current Month = CALCULATE(
        'Costs Summary Table'[Sum of measures],
         FILTER(
            'Calendar',
            'Calendar'[Date] >= DATE(YEAR(TODAY()), MONTH(TODAY()), 1) &&
            'Calendar'[Date] <= TODAY() -2
        )
    )
    

    And

    Total Previous Month = 
    CALCULATE(
        'Costs Summary Table'[Sum of measures],
        FILTER(
            'Calendar',
            'Calendar'[Date] >= DATE(YEAR(TODAY()), MONTH(TODAY()) - 1, 1) &&
            'Calendar'[Date] <= DATE(YEAR(TODAY()), MONTH(TODAY()) - 1, DAY(TODAY()-2))
        )
    )
    

    Now, this will not compare the last 30 days but the MoM:

    enter image description here

    Special thanks to Davide Bacci