cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Aku
Frequent Visitor

Rolling 12 month with month slicer

Hi,

 

So I would need to create a bar chart for last 12 months from selected month in slicer that has yyyymm values from month level calendar table. Fact table is also in month level with yyyymm time key. I have tried searching for solution and tried many things but did not manage to get this work so I would like to know if it is even possible to do this and if so how? We are using SSAS data model if that matters. I have previously worked with different reporting platforms but I'm relatively new to DAX and this is really giving me a headache. Would having calendar in date level help? Calendar and fact table have been joined with yyyymm key and I also have a secondary calendar table that is also in month level that has not been joined to any tables to be used with slicer for some visual needs.

 

YYYYMMkpl
2019015
2019026
2019037
20190423
20190546
2019067
20190743
2019085
20190945
20191064
2019112
2019124
2020013
20200246
20200343
2020046
20200545
2020064
20200754
20200845
20200945
20201034
20201134
20201246
20210135
20210253
20210334
20210434
20210546
2021065
20210734
2021084
20210954
20211034
20211134
2021124

 

Here is sample of data, we have multiple rows per month by other key values but for making this work this sample should be enough? So if I selected 202110 from slicer I would get 12 months data with rolling 12 month sums. For example 202110 has sum of 202110 to 202009 and 202109 to 202008 and so on. Here is sample of data I would need to get for the bar chart.

 

YYYYMMkplsum
202011363
202012405
202101437
202102444
202103435
202104463
202105464
202106465
202107445
202108404
202109413
202110492

 

Hopefully I was clear enough with my needs and the sample data is sufficient as well. Would highly appreciate any help with this problem.

1 ACCEPTED SOLUTION
Aku
Frequent Visitor

Hi @ERD ,

 

Thats not exactly what I was looking for. I managed to build this query with help of a friend that works for our need.

 

AvgSum:=
VAR enddate = MAX(Calendar[YYYYMM])
VAR startdate = enddate - 100
VAR avgsum =
CALCULATE(SUM(tablevalues[kpl]),FILTER(ALL(tablevalues), AND(tablevalues[YYYYMM] > startdate, tablevalues[YYYYMM] <= enddate)))/12
RETURN avgsum
Sum_R12:=
VAR enddate = MAX(TimeSelection[YYYYMM])
VAR startdate = enddate - 100
VAR r12sum = tablevalues[avgsum]

RETURN
IF(MIN(Calendar[YYYYMM]) <= startdate,
BLANK(),
IF(MIN(Calendar[YYYYMM]) > enddate,
BLANK(),
r12sum))

 

tablevalues has the YYYYMM and kpl rows, Calendar table is joined by YYYYMM key and TimeSelection table has no join to either table and is used in slicer.

View solution in original post

3 REPLIES 3
Aku
Frequent Visitor

Hi @ERD ,

 

Thats not exactly what I was looking for. I managed to build this query with help of a friend that works for our need.

 

AvgSum:=
VAR enddate = MAX(Calendar[YYYYMM])
VAR startdate = enddate - 100
VAR avgsum =
CALCULATE(SUM(tablevalues[kpl]),FILTER(ALL(tablevalues), AND(tablevalues[YYYYMM] > startdate, tablevalues[YYYYMM] <= enddate)))/12
RETURN avgsum
Sum_R12:=
VAR enddate = MAX(TimeSelection[YYYYMM])
VAR startdate = enddate - 100
VAR r12sum = tablevalues[avgsum]

RETURN
IF(MIN(Calendar[YYYYMM]) <= startdate,
BLANK(),
IF(MIN(Calendar[YYYYMM]) > enddate,
BLANK(),
r12sum))

 

tablevalues has the YYYYMM and kpl rows, Calendar table is joined by YYYYMM key and TimeSelection table has no join to either table and is used in slicer.

ERD
Memorable Member
Memorable Member

Hi @Aku ,

Here are 3 measures that you can use:

kpl amt = SUM ( T[kpl] )
kpl amt filtered =
CALCULATE (
    [kpl amt],
    FILTER (
        Date_montly,
        Date_montly[MonthYearNum] >= SELECTEDVALUE ( MonthYearNum[MonthYearNum] )
    )
)
rolling kpl =
CALCULATE (
    [kpl amt filtered],
    'Date_montly'[MonthYearNum] <= SELECTEDVALUE ( 'Date_montly'[MonthYearNum] )
)

ERD_0-1634911128274.png

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Stand with Ukraine!

Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Aku
Frequent Visitor

Topic was flagged as spam for a day so I will reply to bring it back to top for better visibility as I would need to finish this report so I can publish it.

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

BizApps LATAM 2023

Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

Power Platform Bootcamp

Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.

Top Solution Authors
Top Kudoed Authors