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
vejas
Helper I
Helper I

12 month rolling sales no future dates

I am trying to get rolling 12 month sales, and i want to hide future dates. 

 

SALES12M = CALCULATE (
[Sales]; CALCULATETABLE (
DATESBETWEEN (
'Calendar'[Date];
NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE ( 'Calendar'[Date] ) ) );
LASTDATE ( 'Calendar'[Date] ));'Calendar'[DatesWithSales] = TRUE()))
 
Problem is where fututre dates starts it shows all sales .
 
 
YtiYuuTj5P.png
 
What is wrong with this approach ?
 
Sinceraly 
1 ACCEPTED SOLUTION
vejas
Helper I
Helper I

Solution that works for me. Combine from 2 articles 

https://www.sqlbi.com/articles/rolling-12-months-average-in-dax/

https://www.sqlbi.com/articles/hiding-future-dates-for-calculations-in-dax/

 

Rolling 12 months sales =
VAR Sales12 = CALCULATE (
[Sales];CALCULATETABLE(
DATESBETWEEN (
'Calendar'[Date];
NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE ( 'Calendar'[Date] ) ) );
LASTDATE ( 'Calendar'[Date] )
);'Calendar'[DatesWithSales]=TRUE())
)
VAR NoFutureDate = MAX('Calendar'[DatesWithSalesNumber])
Return
Sales12*NoFutureDate

View solution in original post

6 REPLIES 6
vejas
Helper I
Helper I

Solution that works for me. Combine from 2 articles 

https://www.sqlbi.com/articles/rolling-12-months-average-in-dax/

https://www.sqlbi.com/articles/hiding-future-dates-for-calculations-in-dax/

 

Rolling 12 months sales =
VAR Sales12 = CALCULATE (
[Sales];CALCULATETABLE(
DATESBETWEEN (
'Calendar'[Date];
NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE ( 'Calendar'[Date] ) ) );
LASTDATE ( 'Calendar'[Date] )
);'Calendar'[DatesWithSales]=TRUE())
)
VAR NoFutureDate = MAX('Calendar'[DatesWithSalesNumber])
Return
Sales12*NoFutureDate
Ashish_Mathur
Super User
Super User

Hi,

Share some data, explain the question and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
leed
Advocate II
Advocate II

Hi @vejas 

 

SQLBI recently has published a blog about this kind of calculation: https://www.sqlbi.com/articles/previous-year-up-to-a-certain-date/

 

You can simply add a calculated column which contains 'Date'[IsPast] = TRUE in your formula and the result should show up correctly.

 

Best,

I dont want to compare periods i want shift back 12 moths every month and calculate sales. Just don't want sales be calculated for future months because they dont have full 12 moths yet. 

@vejas  My bad explanation.

I mean you can use the principle describes in the blog, but not all.

So in your fact table, you create :

IsPast =
VAR LastSaleDate = MAX ( Sales[Order Date] )
VAR LastSaleDatePY = EDATE ( LastSaleDate, -12 )
RETURN
    'Date'[Date] <= LastSaleDatePY
 
and then in your measure, you just need to add:
'Date'[IsPast] = TRUE
 

My new aproach is to make a calculated column in calendar table 

DatesWithSalesNumber = IF('Calendar'[Date] <= MAX (Sales[OrderDate]);1), so if there are no sale no value in column.
I multiply formula result by DatesWithSalesNumber in did not get any number for future dates.

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.