cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Blacksmith354
Frequent Visitor

Dynamically set date picker range with buttons?

I currently have a two date pickers which filter the date column of a gallery. One date picker is the start date and the other is the end date to filter.

 

How can I use a variable to dynamically filter the dates of the date picker?

 

The two dynamic ranges I'd like to set with two separate buttons are:

This whole month 

Last whole month

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @Blacksmith354 ,

 

The variable is only one.

And you can put it inside your OnSelect button.

 

buttonThisMonth :

UpdateContext({varThisMonth: true})

 

buttonLastMonth :

UpdateContext({varThisMonth: false})

 

And this is for the datepicker DefaultDate with switch :

Switch(varThisMonth,
true, Date(Year(Today()),Month(Today()),1),
false, DateAdd(Date(Year(Today()),Month(Today()),1), -1, Months))

 

View solution in original post

4 REPLIES 4
rizkyaditya
Resolver III
Resolver III

Hello @Blacksmith354 ,

 

You can try this inside the DefaultDate property of your date picker :

Switch(yourVariable,
yourVariableValue1, Date(Year(Today()),Month(Today()),1),
yourVariableValue2, DateAdd(Date(Year(Today()),Month(Today()),1), -1, Months))

 

I hope this helps!

@rizkyaditya 

 

This suggestion seems to involve 3 variables and a switch. But I'm lost on how and where to put and set these variables as.

Hello @Blacksmith354 ,

 

The variable is only one.

And you can put it inside your OnSelect button.

 

buttonThisMonth :

UpdateContext({varThisMonth: true})

 

buttonLastMonth :

UpdateContext({varThisMonth: false})

 

And this is for the datepicker DefaultDate with switch :

Switch(varThisMonth,
true, Date(Year(Today()),Month(Today()),1),
false, DateAdd(Date(Year(Today()),Month(Today()),1), -1, Months))

 

View solution in original post

Blacksmith354
Frequent Visitor

@rizkyaditya I was able to easily use this to create two variables since there are two date pickers. Thank you.

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,123)