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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.