cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
peterhui50
Helper III
Helper III

Is this possible? DATEINPERIOD not working the way I expected

Hello,

 

I have a dataset here that is linked to a date table.

 

 

 

peterhui50_0-1647023043365.png

 

What I want to do is to do a rolling 12 month addition. 

 

So I created a measure

```

Sales_12_Months =
CALCULATE (
[Sales],
DATESINPERIOD ( DATE_TABLE[Date], LASTDATE ( DATE_TABLE[Date] ), -12, MONTH )
) ```
 
but when I added in the Year, this measure started to work differently than expected. It's likely it is because the year is added, so it filters differently.
 
peterhui50_3-1647023670999.png

 

 

Is this possible? 

 
Thanks!
 
1 ACCEPTED SOLUTION

I just did a SWITCH statement to include an additional column to specify what is "CURRENT PERIOD" vs "PREVIOUS PERIOD" and just did visual level filter. It's a bit easier.

View solution in original post

3 REPLIES 3
littlemojopuppy
Super User
Super User

Hi @peterhui50 is that first snip your actual dataset?  Because it looks like an Excel pivot table (which summarizes data).  And your rolling 12 month looks correct.

 

 

Looks like this worked
 
Sales_12_Months =
CALCULATE([Sales],DATESINPERIOD(DATE_TABLE[Date],ENDOFYEAR(DATE_TABLE[Date],"2/28"),-12,MONTH))

I just did a SWITCH statement to include an additional column to specify what is "CURRENT PERIOD" vs "PREVIOUS PERIOD" and just did visual level filter. It's a bit easier.

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Top Solution Authors