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.
YYYYMM | kpl |
201901 | 5 |
201902 | 6 |
201903 | 7 |
201904 | 23 |
201905 | 46 |
201906 | 7 |
201907 | 43 |
201908 | 5 |
201909 | 45 |
201910 | 64 |
201911 | 2 |
201912 | 4 |
202001 | 3 |
202002 | 46 |
202003 | 43 |
202004 | 6 |
202005 | 45 |
202006 | 4 |
202007 | 54 |
202008 | 45 |
202009 | 45 |
202010 | 34 |
202011 | 34 |
202012 | 46 |
202101 | 35 |
202102 | 53 |
202103 | 34 |
202104 | 34 |
202105 | 46 |
202106 | 5 |
202107 | 34 |
202108 | 4 |
202109 | 54 |
202110 | 34 |
202111 | 34 |
202112 | 4 |
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.
YYYYMM | kplsum |
202011 | 363 |
202012 | 405 |
202101 | 437 |
202102 | 444 |
202103 | 435 |
202104 | 463 |
202105 | 464 |
202106 | 465 |
202107 | 445 |
202108 | 404 |
202109 | 413 |
202110 | 492 |
Hopefully I was clear enough with my needs and the sample data is sufficient as well. Would highly appreciate any help with this problem.
Solved! Go to Solution.
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.
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.
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] )
)
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!
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.