Forum Discussion

jwisrael's avatar
jwisrael
Frequent Visitor
5 years ago
Solved

Comparing Current and Past Year Sales

Hello,   I'm struggling with a DAX Calculation that would allow me to calculate my current years Sales for only the customers that had sales in the previous year, and who's Product Group is the sam...
  • PaulOlding's avatar
    5 years ago

    This measure first builds a table of combinations of Customer and Product that existed last year, then applies that as a filter when calculating the sales amount.

     

     

    Like-for-like Sales =
    VAR _PreviousYearCombinations =
    CALCULATETABLE(
    SUMMARIZE(Sales, Sales[Customer Name], Sales[Product Group]),
    PREVIOUSYEAR('Date'[Date])
    )
    VAR _Result =
    CALCULATE(
    SUM(Sales[Sales]),
    FILTER(Sales,
    (Sales[Customer Name], Sales[Product Group]) IN (_PreviousYearCombinations)
    )
    )
    RETURN
    _Result