Forum Discussion
Matrix with dynamic column value.
- 1 year ago
Hi,
I have solved a similar question in the attached PBI file.
Hi GFire ,
To achieve a dynamic date range that includes the prior month, you can create a DAX measure and apply it as a filter to your matrix visual. This approach will make the matrix automatically show both the selected month and the entire previous month based on your slicer selections.
First, you'll need to create a new measure in your Power BI model. In the formula bar, you should enter the following DAX expression. It's important to replace 'Date'[Year], 'Date'[MonthNumberOfYear], and 'Date'[Date] with the actual column names from your own date table.
Show Date Range =
VAR SelectedYear = SELECTEDVALUE('Date'[Year])
VAR SelectedMonth = SELECTEDVALUE('Date'[MonthNumberOfYear])
VAR StartDate = DATE(SelectedYear, SelectedMonth - 1, 1)
VAR EndDate = EOMONTH(DATE(SelectedYear, SelectedMonth, 1), 0)
VAR CurrentDateInMatrix = MAX('Date'[Date])
RETURN
IF(
CurrentDateInMatrix >= StartDate && CurrentDateInMatrix <= EndDate,
1,
BLANK()
)
After you have created this measure, select your matrix visual on the report canvas. Drag the new [Show Date Range] measure into the "Filters on this visual" section of the Filters pane. Set the filter condition to "is not blank" and click "Apply filter". Once this is done, your matrix will dynamically update. For example, with May 2025 selected in your filters, the matrix columns will now correctly display all days from both April 2025 and May 2025.
Best regards,
Sorry,..
Only the month of May appears instead of the month of April.