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
User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (2,193)