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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Prior/Last Year DAX same as Current Year

Good day

 

Can someone please advise where I am going wrong trying to calculate prior year values in my three dax-formulas below?

 

These three Sales LY should generate the same value, but it is giving me the same value as the CY.

 

PBI BY YEar.png

 

 

Sales LY:=
CALCULATE(
[Sales] ,
PARALLELPERIOD( 'SSAS V_DIM_AccountingPeriod'[ReportingDateEnd2],-1,YEAR))

 

Sales LY 2:=
CALCULATE(
[Sales] ,
SAMEPERIODLASTYEAR( 'SSAS V_DIM_AccountingPeriod'[ReportingDateEnd2]))

 

Sales LY 3:=
CALCULATE(
[Sales] ,
DATEADD( 'SSAS V_DIM_AccountingPeriod'[ReportingDateEnd2],-1,YEAR))

 

The Fact table that contains the Sales values contains the following keys to two date DIM tables, (DIM_AccountingPeriod and DIM_Time) :

- PeriodNo_SK,
- FinDateID

 

DIM_AccountingPeriod looks as follows and joins on PeriodNo_SK to PeriodNo_SK on the Fact table

 

dim acc.png

 

DIM_Time looks as follows and joins on ID to FinTimeID on the Fact table

 

dim time.png

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Try this formula. 'Table' is data table and 'date' is date table. I create a year column in the date table.

Measure 2 = CALCULATE(SUM('Table'[value]),FILTER('Table',YEAR('Table'[date])=SELECTEDVALUE('date'[year])-1))

 2.PNG

1.PNG

 

Best Regards,

Jay

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @Anonymous ,

 

Try this formula. 'Table' is data table and 'date' is date table. I create a year column in the date table.

Measure 2 = CALCULATE(SUM('Table'[value]),FILTER('Table',YEAR('Table'[date])=SELECTEDVALUE('date'[year])-1))

 2.PNG

1.PNG

 

Best Regards,

Jay

nvprasad
Solution Sage
Solution Sage

Hi,

 

Continuous dates are required for all time intelligence calculations. Kindly use the date or calendar table to pass date.

 

Appreciate a Kudos! 🙂
If this helps and resolves the issue, please mark it as a Solution! 🙂

Regards,
N V Durga Prasad

Did I answer your question? Mark my post as a solution! Appreciate your Kudos.
Follow me on LinkedIn.
Anonymous
Not applicable

Hi @nvprasad 

 

Dim_Time is my date table. Can you see something wrong with it? What should I check on it?

 

dim time 2.png

 

I converted the DAX formulas to pass Dim_Time and not Dim_AccountingPeriod since Dim_Time has continuous dates, but I get the following:

 

PBI 2.png

 

on the Dim_Time table there are multiple companies/systems which has their own continuous set of dates - could this be an issue? In case it had an issue with multiple entries of a specific date (eg 1/1/2001 for company a, company b and company c), I deleted the other companies so that there is eg on one 1/1/2001 in the Dim_Time table. But that did not solve my problem.

@nvprasad , You need to use a date table in all such cases.

refer example

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))

 

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

 

Please provide your feedback comments and advice for new videos
Tutorial Series Dax Vs SQL Direct Query PBI Tips
Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi @amitchandak 

 

I used these two of your suggestions for Last Year Sales, but they dont work.

 

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))

Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))

 

What does "12/31" mean? the syntax seems wrong. Visual studio gives an error when used verbatim.

Anonymous
Not applicable

Hi @amitchandak 

 

Dim_Time is my date table. Can you see something wrong with it? What should I check on it?

 

dim time 2.png

 

I converted the DAX formulas to pass Dim_Time and not Dim_AccountingPeriod since Dim_Time has continuous dates, but I get the following:

 

PBI 2.png

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.