Forum Discussion

alexSPY's avatar
alexSPY
Icon for Helper II rankHelper II
9 years ago
Solved

Prior year, year to date sales

It seems that many people are struggling to accomplish this. I'm trying to show a comparison in a table with this year's sales, and last year over the same time. This year is simple, but last year is...
  • alexSPY's avatar
    9 years ago

    I was able to build a solution using the following measure:

     

    PY YTD Net Sales =
    CALCULATE(
    SUM(Sales[NET SALES]),
    SAMEPERIODLASTYEAR(
    DATESYTD(Date2[Date])
    ),
    FILTER(
    ALL(Date2),
    Date2[MONTH NUMBER] <= (MONTH(NOW())-1)
    )
    )+
    CALCULATE(
    SUM(Sales[NET SALES]),
    SAMEPERIODLASTYEAR(
    DATESYTD(Date2[Date])
    ),
    FILTER(
    ALL(Date2),
    Date2[MONTH NUMBER] = MONTH(NOW())
    && Date2[DAY] <= DAY(NOW())
    )
    )

     

    The key was adding in the current month as a separate function. Without this, I was getting the sum of an entire months sales in the current month for the previous year.