Forum Discussion
Look back 365 days calculation
Hi everybody,
I have a table with dates, dollar value and category of each transaction. I want to see my margin for the past 12 months - but each data point on my chart (example below) should calculate back 12 months.
For example if I look at my % for September 2019 it should consider the previous 12 months on the calculation.
The table looks pretty much like the below example. I also would like to sum for the past 12 months only for the "Sales" category. Can somebody please help me out with this? Thank you!!
| date | total | category |
| 1/1/2019 | $ 50.00 | sale |
| 12/8/2018 | $ 100.00 | taxes |
| 3/5/2019 | $ 150.00 | freight |
| 1/1/2019 | $ 50.00 | sale |
| 12/8/2018 | $ 100.00 | taxes |
| 3/5/2019 | $ 150.00 | freight |
| 1/1/2019 | $ 50.00 | sale |
| 12/8/2018 | $ 100.00 | taxes |
| 12/9/2018 | $ 150.00 | freight |
Add a calendar table and build relationship, then add measure below.
Measure = CALCULATE ( SUM ( 'Table'[total] ), DATESINPERIOD ( 'Calendar'[date], MAX ( 'Calendar'[Date] ), -12, MONTH ), 'Table'[category] = "sale" )
2 Replies
- amitchandak
Super User
try
Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date Filer],ENDOFMONTH(Sales[Sales Date]),-12,MONTH))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 Blog -
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-trend/ba-p/882970
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p/881739
https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601 - v-chuncz-msft
Community Support
Add a calendar table and build relationship, then add measure below.
Measure = CALCULATE ( SUM ( 'Table'[total] ), DATESINPERIOD ( 'Calendar'[date], MAX ( 'Calendar'[Date] ), -12, MONTH ), 'Table'[category] = "sale" )