Forum Discussion
Rolling Value For Last 3 Months
- 1 year ago
Hi,
Try this approach
- Create a Calendar Table with calculated column formulas for Year, Month name and Month number. Sort the Month name by the Month number column
- Create a relationship (Many to One and Single) from the Date column of the Fact table to the Date column of the Calendar table
- To your visual, drag Year and Month name from the Calendar table
- Write these measures
C = sum(Data[Cost])
T = sum(Data[Tonne])
CPT = divide([C],[T])
R3M C = calculate([C],datesbetween(calendar[date],edate(min(calendar[date]),-2),max(calendar[date])))
R3M T = calculate([T],datesbetween(calendar[date],edate(min(calendar[date]),-2),max(calendar[date])))
R3M CPT = divide([R3M C],[R3M T])
Hope this helps.
ssab_wenx Try using
DAX
Rolling3MonthCost =
CALCULATE(
SUM('table'[cost]),
DATESINPERIOD(
'table'[createdate],
MAX('table'[createdate]),
-3,
MONTH
)
)
DAX
Rolling3MonthTon =
CALCULATE(
SUM('table'[ton]),
DATESINPERIOD(
'table'[createdate],
MAX('table'[createdate]),
-3,
MONTH
)
)
DAX
Rolling3MonthCostPerTon =
DIVIDE(
[Rolling3MonthCost],
[Rolling3MonthTon],
0
)
- ssab_wenx1 year agoFrequent Visitor
Hi, thanks for your reply but it doesn't works. As for the cost, it keeps the current row value and not calculate the total cost of last 3 months. For the "MAX('table'[createdate])", what does it mean? I think it should be the current row data value. Could you help take a look? Thanks!