daxmeasures

DAX - Calculate between two dates - Not getting results


I want to calculate the SUM(AMOUNT) between the beginning of the previous month (01-05-2018) and the DATEADD([Date];-1;MONTH) (21-05-2018). For that I'm using this:

CALCULATE (
    SUM(AMOUNT);
    FILTER (dataset; MAX(dataset[Date]) <= DATEADD(dataset[Date];-1;MONTH));
    FILTER (dataset; MIN(dataset[Date]) >= STARTOFMONTH(DATEADD(dataset[Date];-1;MONTH))))

But I'm getting 0 rows on chart with this measure. My dataset only have 2 coluns:

AMOUNT
Date

Can you resolve this issue?


Solution

  • I think you want your formula to look more like this:

    CALCULATE (
        SUM([AMOUNT]);
        FILTER (dataset;
            dataset[Date] <= DATEADD(dataset[Date];-1;MONTH) &&
            dataset[Date] >= STARTOFMONTH(DATEADD(dataset[Date];-1;MONTH))))