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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. 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 )
)
)
 
 


Microsoft MVP



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.




LinkedInVisit my LinkedIn page




Outlook BookingSchedule 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 )
)
)
 
 


Microsoft MVP



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.




LinkedInVisit my LinkedIn page




Outlook BookingSchedule a short Teams meeting to discuss your question



Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors