Filter date ranges based on text filter value
Having an issue building a Filter dropdown with ‘names’ that aggregate dates. I get a feeling it’s a Power BI concept I’m not grasping. Have search many solutions for many days. This is what I currently have:
A separate table with the following “Selection” values (with their intent):
- Current Reporting Month (The previous month)
- Previous Month (2 months ago)
- Last Three months (not including current month)
The Column used in a table for this Filter:
mm_slicer =
IF(HASONEFILTER(Date_Slicer[Selection]),
SWITCH(SELECTEDVALUE(Date_Slicer[Selection]),
"Current Reporting Month", tbl_MetricsMerge[mm_sum_UnplannedMinutes_current],
"Previous Month", tbl_MetricsMerge[mm_sum_UnplannedMinutes_previous],
"Last 3 Months", tbl_MetricsMerge[mm_sum_UnplannedMinutes_last3]
),
tbl_MetricsMerge[mm_sum_UnplannedMinutes_current]
)
DAX for the three values mentioned above:
- mm_sum_UnplannedMinutes_current = CALCULATE(SUM('tbl_MetricsMerge'[MetricResult]),'tbl_MetricsMerge'[Metric] = "Unplanned Downtime Minutes" , DATEDIFF (tbl_MetricsMerge[Date], TODAY (), MONTH) = 1)
- mm_sum_UnplannedMinutes_previous = CALCULATE(SUM('tbl_MetricsMerge'[MetricResult]),'tbl_MetricsMerge'[Metric] = "Unplanned Downtime Minutes" , DATEDIFF (tbl_MetricsMerge[Date], TODAY (), MONTH) = 2)
- mm_sum_UnplannedMinutes_last3 = CALCULATE(SUM('tbl_MetricsMerge'[MetricResult]),'tbl_MetricsMerge'[Metric] = "Unplanned Downtime Minutes", DATEDIFF (tbl_MetricsMerge[Date], TODAY (), MONTH) <= 3)
I can load these measures individually into a table, and see the values as needed. Wonderful – thumbs up.
HOWEVER, when using the mm_slicer measure in a table that applies the Filter, the first “current” and “previous” work, but the “last3” does not, it will only display the third month. How can I get a rolling value of 3 months?
Issues to be resolved:
- Calculate a 3-month rolling sum (Previous month plus 2 more)
- Filter to count only a specific type of value (Unplanned Downtime Minutes)
PS: The tbl_MetricsMerge dataset contains the first day of every month for 2022 (which is used as a placeholder in the data entry form this data is attached to.)
PSS: I have a "Date" table.
I had a relationship link from the Date Selector to the Date Table. Removing that made all this work.