Forum Discussion
Trailing 12-Month Units in Calculated Column - Lower Bound Not Working
Hi All,
I have a table I created called Red Products using CALCULATETABLE and SUMMARIZE referencing my Total Sales by Year table, which has the raw data I've queried in. In my calculated table, I have several columns including the transaction date and customer number. I created a calculated column using the following code to calculate the trailing 12 months of units of a specifc product:
- Anonymous6 years ago
Hi PowerPirate,
I'd like to suggest you take a look at the following blog about using date function to manually define filter range to achieve rolling calculations. They should more accuracy and have better customization than time intelligence functions:
Time Intelligence "The Hard Way" (TITHW)
Regards,
Xiaoxin Sheng
2 Replies
- amitchandak
Super User
To have rolling, always prefer to have a date table and use Time Intelligence.
Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(Sales[Sales Date]),-12,MONTH)) Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],max(Sales[Sales Date]),-12,MONTH)) Rolling 3 till last month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd(Sales[Sales Date],-1,month)),-3,MONTH)) Rolling 3 till last 2 month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd(Sales[Sales Date],-2,month)),-3,MONTH)) Rolling 3 till last month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd('Date'[Date],-1,month)),-3,MONTH)) Rolling 3 till last 2 month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd('Date'[Date],-2,month)),-3,MONTH)) Rolling 3 till last month = Var _max = maxx('Date',ENDOFMONTH(dateadd('Date'[Date],-1,month))) return CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],_max,-3,MONTH)) //CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],_max,-3,MONTH))To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Proud to be a Datanaut Connect on Linkedin - AnonymousNot applicable
Hi PowerPirate,
I'd like to suggest you take a look at the following blog about using date function to manually define filter range to achieve rolling calculations. They should more accuracy and have better customization than time intelligence functions:
Time Intelligence "The Hard Way" (TITHW)
Regards,
Xiaoxin Sheng