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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
sashaxiv
Frequent Visitor

DAX - Sales Comparison (Calculate - Userelationship - SUMX)

Morning all,

I would like to compare sales between stores in the same situation (Feature X flag) in both years (2021 vs 2019). Something similar to next table:

 

sashaxiv_0-1633962974717.png

I have a relationship between sales and dates. For each date I have a column that allows me to know sales in the equivalent day of 2020 (default) and 2019. 

 

  1. Getting data in 2021 in stores with Feature X is easy: SUMX(sales * hasPropertyX)
  2. Getting data in 2019 in stores with Feature X is straighforward as well: CALCULATE(SUMX(sales * hasPropertyX), USERELATIONSHIP(Sales[date], Dates[SameDate2019))

 

My question is, how can i get sales in 2021 in stores with Feature X in 2021 and 2019 (like for like stores)?

My measure in point "1" takes into account stores 1 and 2, so it is incorrect. Only stores 3 and 4 sould be taken into account.

 

Thanks in advance!

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

please check the below picture and the attached pbix file.

 

Picture1.png

 

Sales with feature X : =
VAR currentyear =
MAX ( 'Calendar'[Year] )
VAR newtable =
VALUES ( Codes[Code] )
VAR add_featurecolumn =
SUMMARIZE (
FILTER (
ADDCOLUMNS (
newtable,
"@feature", CALCULATE ( AVERAGE ( Data[HasPropertyX] ), REMOVEFILTERS ( 'Calendar' ) )
),
[@feature] = 1
),
Codes[Code]
)
RETURN
IF (
HASONEVALUE ( 'Calendar'[Month & Year] ),
CALCULATE ( SUM ( Data[Sales] ), add_featurecolumn ),
DIVIDE (
CALCULATE ( SUM ( Data[Sales] ), add_featurecolumn, 'Calendar'[Year] = 2021 )
- CALCULATE ( SUM ( Data[Sales] ), add_featurecolumn, 'Calendar'[Year] = 2019 ),
CALCULATE ( SUM ( Data[Sales] ), add_featurecolumn, 'Calendar'[Year] = 2019 )
)
)
 
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi,

please check the below picture and the attached pbix file.

 

Picture1.png

 

Sales with feature X : =
VAR currentyear =
MAX ( 'Calendar'[Year] )
VAR newtable =
VALUES ( Codes[Code] )
VAR add_featurecolumn =
SUMMARIZE (
FILTER (
ADDCOLUMNS (
newtable,
"@feature", CALCULATE ( AVERAGE ( Data[HasPropertyX] ), REMOVEFILTERS ( 'Calendar' ) )
),
[@feature] = 1
),
Codes[Code]
)
RETURN
IF (
HASONEVALUE ( 'Calendar'[Month & Year] ),
CALCULATE ( SUM ( Data[Sales] ), add_featurecolumn ),
DIVIDE (
CALCULATE ( SUM ( Data[Sales] ), add_featurecolumn, 'Calendar'[Year] = 2021 )
- CALCULATE ( SUM ( Data[Sales] ), add_featurecolumn, 'Calendar'[Year] = 2019 ),
CALCULATE ( SUM ( Data[Sales] ), add_featurecolumn, 'Calendar'[Year] = 2019 )
)
)
 
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.