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
Exciting changes

Power BI Community Changes

Check out the changes to the Power BI Community announced at Build.

May 2023 update

Power BI May 2023 Update

Find out more about the May 2023 update.

Kudo Data Story carousel

Data Stories Gallery

Visit our Data Stories Gallery and give kudos to your favorite Data Stories.

Top Solution Authors