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
george1
Frequent Visitor

Date Picker slicer with relative date

Hello, I need one help. @RossEdwards , @visheshjain , @collinq , @MiquelPBI , @mariussve1 

I have data like this, here I have  4 different date options:

 

Untitled2.png

 

Now without changing the style of the data I would like to create a date picker option like this,

Data.png

Here user can pick the option the would like and based on this selection they will get relative date filter,

Untitled.png

And then they can filter the data and shows only one field in the table view, whaever the charges associated with it with selected date,

Untitled1.png

How can I achieve that? If use picked 2 months in relative date slicer and change the date option to Post date then I would table to display 2 months of data of Post date. Can someone please help on how can I achieve this? Please and thanks.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks for the reply from  DataNinja777 and MiquelPBI  , please allow me to provide another insight:

Hi, @george1 

Based on my testing, parameters cannot be converted to the relative time type in a slicer. Therefore, your slicer must be derived from one of the columns in your data table. This is likely why you are encountering errors, as one of your slicers is derived from parameters, while the relative time type is from a fixed column.

 

I have provided an alternative solution for you:

 

1.Firstly, create the following measure:

MEASURE = 
VAR diff = 10
VAR selectid =
    MAX ( 'Parameter'[Parameter Order] )
VAR column1d =
    CALCULATE ( MAX ( 'Table'[Column1] ), ALLSELECTED ( 'Table' ) )
VAR column2d =
    CALCULATE ( MAX ( 'Table'[Column2] ), ALLSELECTED ( 'Table' ) )
RETURN
    SWITCH (
        TRUE (),
        selectid = 0,
            IF ( MAX ( 'Table'[Column1] ) >= column1d - diff, 1, 0 ),
        selectid = 1,
            IF ( MAX ( 'Table'[Column2] ) >= column2d - diff, 1, 0 ),
        1
    )

2.Secondly, apply the measure to the visual object:

 

vlinyulumsft_0-1726738220854.png

 

3.Here's my final result, which I hope meets your requirements.

vlinyulumsft_1-1726738220855.png

vlinyulumsft_2-1726738238488.png

 

Please find the attached pbix relevant to the case.

 
Of course, if you have any new ideas, you are welcome to contact us.
 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

10 REPLIES 10
MiquelPBI
Helper I
Helper I

I believe you can accomplish this with a combination of measures and a field parameter.  This is what the model would look like. 

 

MiquelPBI_3-1726507609189.png

1. Create relationships between a calendar table and the three dates in a fact table.  Note, one relationship will be active and two will be inactive.  Note the image of model above.   

 

2. Write measures for each date column you want to calculate.  To my previous point you'll write measures to look at the inactive relationships. That said, measures you write will respect the active relationship unless you tell the measure to look at the inactive.

MiquelPBI_0-1726507501559.png

 

3. Create a field parameter that uses the measures you created.  Field parameters are a wonderful technique to create dynamic displays and filters.  This table is disconnected in the model.  Note the model image at beginning of post.

MiquelPBI_1-1726507522263.png

 

4. Drop the date column from your calendar table in slicer for the date slicer. Drop the field parameter column into a slicer.  Drop the same field paramter column in your table visual.  

MiquelPBI_2-1726507574360.png

 

I hope that helps!

 

 

Yes, the dates will remain as selected and the user can select and show multiple date columns.  


I dont see a way to attach a file.  I'm assuming I'll have to add it to my Git repo and share a link.  I can do that but will have to wait until later. Sorry.  

Hi @MiquelPBI , Oh I see. Sure, I can wait and really appriciate your help in this. Once I get the pbix file it will help me to understand little better way.

So in my table there are about 7-8 measures. So do I need to do this for every measures?

Hi @MiquelPBI , Is it possible to attach pbix file here? If you can it will help a great deal. 

Do you think with this selection of date does stay when I change one date option to another.

Example: I have selected date of service and then I pick date 6/27/2023. Now if I change date from date of service to Posting date then my date changes to select all. what I want that time is my date 6/27/2023 to stay when I change from Date of Service to Posting Date.

If I change it to relative date then if for example my date selection is last 2 months and I change to Posting date then selection stays to last 2 months but my table view displays all available dates which I don't want. If my relative date slicer says last 2 months than table view also should display last 2 months of data when I change Date of Service to Posting date.

 

If you can attach pbix file it would be great. Please

george1
Frequent Visitor

Hi @DataNinja777 , this looks very interesting. I have a couple of questions:

1) In your code you mentioned create disconnected date table, with below function:

DateTable = CALENDAR(MIN('YourTable'[Encounter Date]), MAX('YourTable'[Coded Date]))

 Why do I need to take only this two fields from the date? Because sometimes Coded Date as max available value and sometimes Date of Service has max value. Then why do I need to take only this two in the mix?

 

2) I do have many measures, like 7 or 8 measures. So do I need to create this kind (SelectedDateMeasure) for 7 or 8 times?

 

And also do you have pbix file and if you can attach it here then I can have a look at the reference as well. This will help.

DataNinja777
Super User
Super User

@george1 ,

 

You can use a field parameter to allow users to select from multiple date columns and apply the selection to a date picker. Here's how you can do it:

  1. Enable Field Parameters: First, ensure that field parameters are enabled in Power BI. To do this, go to File > Options and settings > Options > Preview features, and check Field parameters.
  2. Create a Field Parameter:
    • In the Modeling tab, click New Parameter > Fields.
    • Select the date columns you want to include in the parameter: "Encounter Date", "Date of Service", "Post Date", "Coded Date"
    • Name the parameter, such as "Date Selector."
  3. Use the Field Parameter:
    • After creating the field parameter, you'll have a slicer in your report where users can choose which date column they want to filter.
    • Create a date picker slicer in Power BI and bind it to the selected date column via the field parameter.

Now, you can switch between different date fields using the parameter, and the selected date column will dynamically apply to the date picker.

 

Best regards,

@DataNinja777 , Thank you so much for the suggestion you provided. I tried this, and it works as you saying but only option I have is, selection of date doesn't stay when I change one date option to another.

Example: I have selected date of service and then I pick date 6/27/2023. Now if I change date from date of service to Posting date then my date changes to select all. what I want that time is my date 6/27/2023 to stay when I change from Date of Service to Posting Date.

If I change it to relative date then if for example my date selection is last 2 months and I change to Posting date then selection stays to last 2 months but my table view displays all available dates which I don't want. If my relative date slicer says last 2 months than table view also should display last 2 months of data when I change Date of Service to Posting date.

Is this something possible? How can I do that? Please help.

Hi @george1 ,

 

You can achieve the desired output by combining field parameters with a slicer set to the relative date option, as shown below. I have generated sample data and recreated the output you’re looking for.

Even if you have multiple measures, you can use the switch function along with a disconnected table of measures to toggle between them seamlessly.

 

DataNinja777_0-1726446571121.png

I have attached an example pbix file for your reference. 

Best regards,

Thanks @DataNinja777 , The only problem I see with this is when I change the date then it doesn't stick.

Like here I have selected this options, Now I change dates to last 10 days and it display correctly,

 

Encounter Date.jpg

 

Now if I change the date option here,

DOS.png

It displays all the available dates when I change the date options even though I have selected last 10 days. Is there any workaround to this?

Anonymous
Not applicable

Thanks for the reply from  DataNinja777 and MiquelPBI  , please allow me to provide another insight:

Hi, @george1 

Based on my testing, parameters cannot be converted to the relative time type in a slicer. Therefore, your slicer must be derived from one of the columns in your data table. This is likely why you are encountering errors, as one of your slicers is derived from parameters, while the relative time type is from a fixed column.

 

I have provided an alternative solution for you:

 

1.Firstly, create the following measure:

MEASURE = 
VAR diff = 10
VAR selectid =
    MAX ( 'Parameter'[Parameter Order] )
VAR column1d =
    CALCULATE ( MAX ( 'Table'[Column1] ), ALLSELECTED ( 'Table' ) )
VAR column2d =
    CALCULATE ( MAX ( 'Table'[Column2] ), ALLSELECTED ( 'Table' ) )
RETURN
    SWITCH (
        TRUE (),
        selectid = 0,
            IF ( MAX ( 'Table'[Column1] ) >= column1d - diff, 1, 0 ),
        selectid = 1,
            IF ( MAX ( 'Table'[Column2] ) >= column2d - diff, 1, 0 ),
        1
    )

2.Secondly, apply the measure to the visual object:

 

vlinyulumsft_0-1726738220854.png

 

3.Here's my final result, which I hope meets your requirements.

vlinyulumsft_1-1726738220855.png

vlinyulumsft_2-1726738238488.png

 

Please find the attached pbix relevant to the case.

 
Of course, if you have any new ideas, you are welcome to contact us.
 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.