Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
jwisrael
Frequent Visitor

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 same as last year. The goal is to eliminate new customers from the calculation and any new Product Groups that a customer purchased this year but not last year. Any help or guidance would be amazing.

 

Date ValueCustomer NameSalesProduct Group
1/5/2020A$1001
2/5/2020A$1501
12/5/2020B$1002
1/4/2021A$1501
1/15/2021A$501
2/20/2021A$752
3/10/2021B$1002
5/4/2021C$2001

 

Thanks,

J

1 ACCEPTED SOLUTION
PaulOlding
Solution Sage
Solution Sage

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.

PaulOlding_0-1620724595064.png

 

 

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

View solution in original post

4 REPLIES 4
PaulOlding
Solution Sage
Solution Sage

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.

PaulOlding_0-1620724595064.png

 

 

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
edhans
Super User
Super User

See if this works @jwisrael 

Here is the basic measure:

Valid Sales = 
VAR varCustomer = MAX('Table'[Customer Name])
VAR varGroup = MAX('Table'[Product Group])
VAR varCurrentYear = MAX('Date'[Year])
VAR varPriorYearData = 
    CALCULATE(
        [Total Sales],
        REMOVEFILTERS('Table'),
        YEAR('Table'[Date Value]) = varCurrentYear - 1,
        'Table'[Product Group] = varGroup,
        'Table'[Customer Name] = varCustomer,
        DATEADD('Date'[Date], -1, YEAR)
    )
RETURN
    varPriorYearData

It returns the "Valid Sales" column:

edhans_0-1620689366233.png

You need a date table to do this - which you can get from here - and note the date table is marked as a date table in the model. https://bit.ly/DateTableByEd

My PBIX file is here.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Thank you for the detailed response! What table would I use for REMOVEFILTERS('Table')?

Your sales table. When I pasted the data in to Power BI, it was just called "Table" so that is what I used in the REMOVEFILTERS. In reality it would be REMOVEFILTERS(Sales) or REMOVEFILTERS('Sales Table') or whatever you call it. I have to do that to be able to access the entire table when applying the customer, group, and then last year's year number to it.

 

If this helped, please mark it as the solution.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.