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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
timzedel
Frequent Visitor

Previous interval date not working

Hi,

 

I am trying to create a measure that returns the previous year's value, using the following expression: 

 

Previous Year Value = CALCULATE([Total Value],
DATEADD('Table'[Year],-1,YEAR
)
)
 
However, when I visualise this in a table, the measure does not work as intended - it only gives the aggregated total, but not the year by year (e.g. 2011 should be blank, 2012 should be 364341500 (2011's value) etc.).
 
timzedel_0-1673266772469.png

 

Can someone please explain what is wrong with my DAX? Power BI is not picking up any errosrs.
 
 
1 ACCEPTED SOLUTION

Hi Mike,

 

The YEAR column in 'Table' has years 2011 - 2022 formatted as date.

 

Sample data here:

 

timzedel_0-1673267928413.png

 

 

I've just created a DimDate table using a simple 

DimDate = SUMMARIZE('Sheet1 (2)','Sheet1 (2)'[Year])

and have used the Year column in DimDate in the DATEADD expression, this seems to have solved the problem.

 

However, I am confused as to why using the Year column in DimDate as opposed to Year column in the original Table made a difference - they were both formatted as date so what was the issue? 

 
 

View solution in original post

3 REPLIES 3
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @timzedel.

 

For using Time Intelligence functions like DATEADD you need columns with dates. I assume you do not have that right? Can please show the dataset below with sample data?

 

Best regards

Michael

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

Hi Mike,

 

The YEAR column in 'Table' has years 2011 - 2022 formatted as date.

 

Sample data here:

 

timzedel_0-1673267928413.png

 

 

I've just created a DimDate table using a simple 

DimDate = SUMMARIZE('Sheet1 (2)','Sheet1 (2)'[Year])

and have used the Year column in DimDate in the DATEADD expression, this seems to have solved the problem.

 

However, I am confused as to why using the Year column in DimDate as opposed to Year column in the original Table made a difference - they were both formatted as date so what was the issue? 

 
 

@timzedel , if you have date table then only then this will work (also you need have date table and use year from date table) 

Previous Year Value = CALCULATE([Total Value],
DATEADD('Date'[Date],-1,Day
)
)

 

Using a separate date/year table

 

//Only year vs Year, not a level below

This Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

 

 

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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