Forum Discussion
Ortignano
Helper II
5 years agolast 12 months standard deviation on a table
Hello, I have a table (product) of product category with Quantity,year,month and monthID inside it (monthID is equal to (year-2006)*12+monthnumber). For example Product Qty Year month A ...
- 5 years ago
Hi, Ortignano
Based on your descirption, I created data to reproduce your scenario. The pbix file is attached in the end.
Tab:
Calendar(a calculated table):
Calendar = ADDCOLUMNS( CALENDARAUTO(), "YM", YEAR([Date])*100+MONTH([Date]) )There is no relationship between two tables. You may create measures as below.
Sum Qty over last 12 Months = var ym = MAX(Tab[YearMonth]) return CALCULATE( SUM(Tab[Qty]), FILTER( ALLEXCEPT(Tab,Tab[Product]), Tab[YearMonth] in TOPN( 12, CALCULATETABLE( DISTINCT('Calendar'[YM]), FILTER( ALL('Calendar'), [YM]<=ym ) ), [YM] ) ) )STDEV Qty over last 12 Months = var ym = MAX(Tab[YearMonth]) return CALCULATE( STDEV.P(Tab[Qty]), FILTER( ALLEXCEPT(Tab,Tab[Product]), Tab[YearMonth] in TOPN( 12, CALCULATETABLE( DISTINCT('Calendar'[YM]), FILTER( ALL('Calendar'), [YM]<=ym ) ), [YM] ) ) )Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
stevedep
Memorable Member
5 years agoCalculate (stdev.p(values(product), calculate (sum(quantity)), datesinperiod(date,-12,month))
Something like this..