Forum Discussion
Calculate SUM between YearMonth (Values)
- 5 years ago
Anonymous Sorry for late reply. Do you mean calculate the sum of last 12 months for every product in every month? If so, try this
Measure 2 = VAR curYearMonth = SELECTEDVALUE('Table'[YearMonth]) VAR curYear = INT(LEFT(curYearMonth,4)) VAR curMonth = RIGHT(curYearMonth,2) VAR previousYearMonth = INT((curYear-1)&curMonth) VAR product = SELECTEDVALUE('Table'[ProductName]) RETURN CALCULATE(SUM('Table'[Value]),ALL('Table'),'Table'[YearMonth]>previousYearMonth,'Table'[YearMonth]<=curYearMonth,'Table'[ProductName]=product)Let me know whether it works or not.
Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.
Thanks for fast replies! I realized I have another column I want to use as external filter since I have several products with a value for each YearMonth. I liked your solution without using a additional table or index column. How would I do this when the table look like the one below?
Anonymous Sorry for late reply. Do you mean calculate the sum of last 12 months for every product in every month? If so, try this
Measure 2 =
VAR curYearMonth = SELECTEDVALUE('Table'[YearMonth])
VAR curYear = INT(LEFT(curYearMonth,4))
VAR curMonth = RIGHT(curYearMonth,2)
VAR previousYearMonth = INT((curYear-1)&curMonth)
VAR product = SELECTEDVALUE('Table'[ProductName])
RETURN
CALCULATE(SUM('Table'[Value]),ALL('Table'),'Table'[YearMonth]>previousYearMonth,'Table'[YearMonth]<=curYearMonth,'Table'[ProductName]=product)
Let me know whether it works or not.
Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.
- Anonymous5 years agoNot applicable
Awesome finally! Thanks a lot! Worked just fine, I just had to change SELECTEDVALUE to MAX since it wasn't available in Power Pivot 🙂