Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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
Anonymous
Not applicable

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
Anonymous
Not applicable

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
Super User
Super User

Hi @Anonymous ,

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. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

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!

Anonymous
Not applicable

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors