Forum Discussion
vshinto
8 months agoRegular Visitor
How to Display Selected Month Plus Previous Two Months Dynamically in Power BI Visuals?
Hello everyone, I have a Power BI report with a date slicer based on a Calendar table. When a user selects a month (e.g., December 2025), I want my visuals (tables and charts) to show data for the ...
Zanqueta
8 months agoSuper User
Hi vshinto
o achieve this dynamic behaviour in Power BI, you need a DAX measure or filter logic that reacts to the selected month and includes the two previous months. Here’s the recommended approach:
Solution Overview
- Use a Calendar table with a continuous date column and a Month-Year column.
- Create a measure or filter that checks if a date falls within the selected month and the two preceding months.
Step 1: Ensure Calendar Table
Your Calendar table should have:
- Date column (continuous)
- YearMonth column (e.g., 2025-12)
- A relationship to your fact table.
Step 2: Create a DAX Measure for Filtering
You can use DATESINPERIOD or DATEADD inside CALCULATE:
SelectedAndPreviousTwoMonths =
VAR LastVisibleDate =
MAX ( 'Calendar'[Date] ) // Última data visível no contexto do slicer
RETURN
CALCULATE (
[Total Sales],
DATESINPERIOD (
'Calendar'[Date],
LastVisibleDate,
-3,
MONTH
)
Step 3: Apply to Visuals
- Use this measure in your visuals.
- If you need to filter rows (e.g., in a table), create a calculated column or use a visual-level filter with a similar logic:
ShowLast3Months =
VAR SelectedDate = MAX ( 'Calendar'[Date] )
RETURN
IF (
'Calendar'[Date] >= EDATE ( SelectedDate, -2 )
&& 'Calendar'[Date] <= SelectedDate,
1,
0
Then filter visuals where ShowLast3Months = 1.
Official reference:
If this response was helpful in any way, I’d gladly accept a 👍much like the joy of seeing a DAX measure work first time without needing another FILTER.
Please mark it as the correct solution. It helps other community members find their way faster (and saves them from another endless loop 🌀.