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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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.


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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.