Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Yacine2025
Frequent Visitor

Need Help

Hi everyone,

 

I need help to achieve my request please 

 

I have a visual matrix in Power BI that contain Client and coutry in row and number for period and last period and gap between thses periods. I want to create 1 slicer with 4 choice (3 months, 2 months, month and custom). I use measure for every choice. I need when I clic on button 1, 2 or 3 months, it select the right measure and if I select custom then the user select date in the filter Date slicer. Thank you in advance.

 

Example below

Yacine2025_2-1749007060106.png

 

 

 

1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi @Yacine2025 ,

 

To create a slicer in Power BI that allows the user to choose between "Last Month," "2 Last months," "3 Last months," and "Custom," start by creating a disconnected table called Period Selector with one column called PeriodOption, using this DAX:

Period Selector = DATATABLE(
    "PeriodOption", STRING,
    {
        {"Last Month"},
        {"2 Last months"},
        {"3 Last months"},
        {"Custom"}
    }
)

Add this table to a slicer visual in your report and set it to horizontal orientation to mimic button selection. Then create a measure to capture the selected value from the slicer:

Selected Period Option = SELECTEDVALUE('Period Selector'[PeriodOption])

Assuming you already have base measures created for each of the period comparisons, such as [Period_LastMonth], [Period_2Months], [Period_3Months], and [Period_Custom], create a unified measure to switch between them dynamically depending on the slicer selection:

Period Dynamic = 
VAR SelectedOption = SELECTEDVALUE('Period Selector'[PeriodOption])
RETURN
SWITCH(
    TRUE(),
    SelectedOption = "Last Month", [Period_LastMonth],
    SelectedOption = "2 Last months", [Period_2Months],
    SelectedOption = "3 Last months", [Period_3Months],
    SelectedOption = "Custom", [Period_Custom],
    BLANK()
)

Repeat the same structure for Last Period:

Last Period Dynamic = 
VAR SelectedOption = SELECTEDVALUE('Period Selector'[PeriodOption])
RETURN
SWITCH(
    TRUE(),
    SelectedOption = "Last Month", [LastPeriod_LastMonth],
    SelectedOption = "2 Last months", [LastPeriod_2Months],
    SelectedOption = "3 Last months", [LastPeriod_3Months],
    SelectedOption = "Custom", [LastPeriod_Custom],
    BLANK()
)

Finally, calculate the GAP as the difference between these two dynamic measures:

GAP Dynamic = [Last Period Dynamic] - [Period Dynamic]

Ensure that the custom period measures like [Period_Custom] and [LastPeriod_Custom] are written using the selected range from the Date slicer. You can do this with DATESBETWEEN using the MIN and MAX of the selected date from your Date table. For example:

Period_Custom = 
CALCULATE(
    SUM('YourTable'[Value]),
    DATESBETWEEN('DateTable'[Date], MIN('DateTable'[Date]), MAX('DateTable'[Date]))
)

This setup gives you a dynamic, user-controlled matrix that updates according to button-style slicer input or custom date selection.

 

Best regards,

 

View solution in original post

5 REPLIES 5
v-karpurapud
Community Support
Community Support

Hi @Yacine2025 

We are following up to see if you have had the chance to review the information provided. If you have any further questions, please do not hesitate to contact us. Could you confirm whether your query has been resolved? If so, kindly mark the helpful response and accept it as the solution to assist other community members in resolving similar issues more efficiently. If not, please provide detailed information so we can better assist you.


Thank You.

v-karpurapud
Community Support
Community Support

Hi @Yacine2025 

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.

Thank you.

v-karpurapud
Community Support
Community Support

Hi @Yacine2025 

Could you please confirm if your query have been resolved the solution provided by @burakkaragoz and @DataNinja777 ? If they have, kindly mark the helpful response and accept it as the solution. This will assist other community members in resolving similar issues more efficiently.

Thank you.

burakkaragoz
Community Champion
Community Champion

Hi @Yacine2025 ,

 

The solution above is pretty solid for dynamic period selection, but just to make things easier, here’s ready-to-use DAX example that calculates days since each customer’s last purchase. You can drop this into your model and adjust table/column names as needed:

dax
 
Days Since Last Purchase = VAR LastPurchaseDate = CALCULATE(
    MAX('Sales'[OrderDate]), 
    ALLEXCEPT('Sales', 'Sales'[Customer])
)
RETURN
DATEDIFF(LastPurchaseDate, TODAY(), DAY)

You can put this measure into table visual with customers to see the exact number of days since each last transaction.
If you want to expand it for dynamic date periods (like “Last Month”, “Last Months”, etc), you can use disconnected table for the period selection and SWITCH statement in DAX, something like this:

dax
 
SelectedPeriod =
SWITCH(
    SELECTEDVALUE('PeriodSelect'[Period]),
    "Last Month", DATESINPERIOD('Date'[Date], TODAY(), -1, MONTH),
    "Last 3 Months", DATESINPERIOD('Date'[Date], TODAY(), -3, MONTH),
    "Last 6 Months", DATESINPERIOD('Date'[Date], TODAY(), -6, MONTH),
    "Custom", // add your own logic for custom periods
    BLANK()
)

If you want, you can mix both approaches—showing days since last purchase, but filter it by the period the user selects.
If you run into any issues, just let me know what your current model looks like or share your DAX, and can help tweak it for you.

If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, would be grateful for 'Kudos' if you found my response helpful.
translation and formatting supported by AI

DataNinja777
Super User
Super User

Hi @Yacine2025 ,

 

To create a slicer in Power BI that allows the user to choose between "Last Month," "2 Last months," "3 Last months," and "Custom," start by creating a disconnected table called Period Selector with one column called PeriodOption, using this DAX:

Period Selector = DATATABLE(
    "PeriodOption", STRING,
    {
        {"Last Month"},
        {"2 Last months"},
        {"3 Last months"},
        {"Custom"}
    }
)

Add this table to a slicer visual in your report and set it to horizontal orientation to mimic button selection. Then create a measure to capture the selected value from the slicer:

Selected Period Option = SELECTEDVALUE('Period Selector'[PeriodOption])

Assuming you already have base measures created for each of the period comparisons, such as [Period_LastMonth], [Period_2Months], [Period_3Months], and [Period_Custom], create a unified measure to switch between them dynamically depending on the slicer selection:

Period Dynamic = 
VAR SelectedOption = SELECTEDVALUE('Period Selector'[PeriodOption])
RETURN
SWITCH(
    TRUE(),
    SelectedOption = "Last Month", [Period_LastMonth],
    SelectedOption = "2 Last months", [Period_2Months],
    SelectedOption = "3 Last months", [Period_3Months],
    SelectedOption = "Custom", [Period_Custom],
    BLANK()
)

Repeat the same structure for Last Period:

Last Period Dynamic = 
VAR SelectedOption = SELECTEDVALUE('Period Selector'[PeriodOption])
RETURN
SWITCH(
    TRUE(),
    SelectedOption = "Last Month", [LastPeriod_LastMonth],
    SelectedOption = "2 Last months", [LastPeriod_2Months],
    SelectedOption = "3 Last months", [LastPeriod_3Months],
    SelectedOption = "Custom", [LastPeriod_Custom],
    BLANK()
)

Finally, calculate the GAP as the difference between these two dynamic measures:

GAP Dynamic = [Last Period Dynamic] - [Period Dynamic]

Ensure that the custom period measures like [Period_Custom] and [LastPeriod_Custom] are written using the selected range from the Date slicer. You can do this with DATESBETWEEN using the MIN and MAX of the selected date from your Date table. For example:

Period_Custom = 
CALCULATE(
    SUM('YourTable'[Value]),
    DATESBETWEEN('DateTable'[Date], MIN('DateTable'[Date]), MAX('DateTable'[Date]))
)

This setup gives you a dynamic, user-controlled matrix that updates according to button-style slicer input or custom date selection.

 

Best regards,

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.