Forum Discussion

vshinto's avatar
vshinto
Regular Visitor
8 months ago
Solved

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 selected month plus the two previous months. For example:

  • If December 2025 is selected → show October, November, and December 2025.
  • If November 2025 is selected → show September, October, and November 2025.

    Thank you.
  • Hi, vshinto , you have try with a disconnected table for display the dimensiones previous values from slicer.

     

4 Replies

  • Hi, vshinto , you have try with a disconnected table for display the dimensiones previous values from slicer.

     

    • vshinto's avatar
      vshinto
      Regular Visitor

      Hello i make something similar this to solve my problem.

      Thank you.

  • 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

    1. Use a Calendar table with a continuous date column and a Month-Year column.
    2. 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 🌀.