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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
NiklasK
New Member

Measure to Calculate Sales from Previous year - Using a Datetable mapping current year to PY Date

Hello together,

 

I am struggling with the following problem.

 

There are two tables: Date and FactSales. The Date table shows the current date and has a mapped date to the previous year. So a simple DATEADD / PREVIOUSYEAR will not work...

NiklasK_0-1731068550716.png

 

 

I would like to create a matrix visual, which displays the following columns. (Sales PY (previous year) should not be empty)

NiklasK_0-1731068180518.png

Using the Selectedvalue function I can successfully map the Date PY to the current date:

NiklasK_1-1731068230015.png

 

NiklasK_2-1731068254766.png

 

NiklasK_3-1731068264781.png

However applying the same logic to the Calculate function ends up returning blank results. Anyone knows what I am doing wrong?

 

Thank you very much

1 ACCEPTED SOLUTION
mh2587
Super User
Super User

Just add LastYearDate column in Date Table and relate it to fact sale which will be inactive and then use the userrelationship() function to activate it virtualy in measure for PY
PreviousYearSales =
CALCULATE(
SUM(Sales[SalesAmount]),
USERELATIONSHIP('Date'[lastYearDate], Sales[SaleDate])
)

or try @johnt75 DAX


Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



View solution in original post

3 REPLIES 3
mh2587
Super User
Super User

Just add LastYearDate column in Date Table and relate it to fact sale which will be inactive and then use the userrelationship() function to activate it virtualy in measure for PY
PreviousYearSales =
CALCULATE(
SUM(Sales[SalesAmount]),
USERELATIONSHIP('Date'[lastYearDate], Sales[SaleDate])
)

or try @johnt75 DAX


Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



johnt75
Super User
Super User

Make sure that your date table has all the dates for all the years you are interested in, and make sure that it is marked as a date table.

Change the relationship between date and the fact table to single direction.

You can then write the sales PY measure as

Sales PY =
CALCULATE ( SUM ( 'Fact_Sales'[Sales] ), DATEADD ( 'Date'[Date], -1, YEAR ) )

I am not looking for an exact comparison but if you have a look at the calendar table, dates are shifted.

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.

Top Solution Authors
Top Kudoed Authors