Forum Discussion
Rolling 12 months
- Anonymous4 years ago
Hi achanikya,
I write a formula to use selection year get the last date from the calendar table and use it as a condition to rolling calculated on the fact table. You can try to use the following measure formula if it is suitable for your requirement:
Sales amount 12 month = //get the selection year from new date table VAR sYear = MAX ( 'To Year'[Year] ) //get the last date with selected year from calendar table VAR selected = CALCULATE ( MAX ( 'Date'[Date] ), FILTER ( ALLSELECTED ( 'Date' ), YEAR ( [Date] ) = sYear ) ) RETURN //rolling calculation CALCULATE ( [Sales Amount], FILTER ( ALLSELECTED ( 'Fact' ), //replace this wiht your fact table [Date] >= DATE ( YEAR ( selected ) - 1, MONTH ( selected ), DAY ( selected ) ) && [Date] <= selected ), VALUES ( 'Fact'[System Name] ) )If the above does not help, can you please share a pbix or some dummy data that keep raw data structure with expected results? They should help us clarify your scenario and test to coding formula.
How to Get Your Question Answered Quickly
Regards,
Xiaoxin Sheng
Hi achanikya,
I write a formula to use selection year get the last date from the calendar table and use it as a condition to rolling calculated on the fact table. You can try to use the following measure formula if it is suitable for your requirement:
Sales amount 12 month =
//get the selection year from new date table
VAR sYear =
MAX ( 'To Year'[Year] ) //get the last date with selected year from calendar table
VAR selected =
CALCULATE (
MAX ( 'Date'[Date] ),
FILTER ( ALLSELECTED ( 'Date' ), YEAR ( [Date] ) = sYear )
)
RETURN
//rolling calculation
CALCULATE (
[Sales Amount],
FILTER (
ALLSELECTED ( 'Fact' ),
//replace this wiht your fact table
[Date]
>= DATE ( YEAR ( selected ) - 1, MONTH ( selected ), DAY ( selected ) )
&& [Date] <= selected
),
VALUES ( 'Fact'[System Name] )
)
If the above does not help, can you please share a pbix or some dummy data that keep raw data structure with expected results? They should help us clarify your scenario and test to coding formula.
How to Get Your Question Answered Quickly
Regards,
Xiaoxin Sheng