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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Helpful resources

Announcements
Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Kudoed Authors