cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Eben98
Advocate II
Advocate II

Date Filters for Last week,months..

Hi guys,

I  created a application, I want to filter the tickets based on  1. last month

                                                                                                 2. last week

                                                                                                 3. last 3 months

                                                                                                 4. current week

                                                                                                  5. current month

                                                                                                  6. current year.

My code is working well for current year, current month and current week. But its not working for the last week,last month, last 3 months . I tried with DateAdd(). But this gives me the exact day for the last month or last 3 months etc..

 

NotStartedDate is of type SingleText.

 

 

Sort(
If(
(!IsBlank(TextInput1)),
(Filter(
TicketCollection,
(StartsWith(
Text(ID),
TextInput1.Text
) && TextInput1.Text in Title) && Trim(EmployeeName) = Trim(User().FullName)
)),
(Dropdown4.SelectedText.Value = "Last month"),
(Filter(
TicketCollection,
Month(
DateValue(
Text(
DateValue(
NotStartedDate,
"fr"
),
"[$-en-US]mm/dd/yyyy"
)
)
) = DateAdd(Now(),-1,Months) && (TaskStatus = TaskStatusDropdown_2.SelectedText.Value || TaskStatusDropdown_2.SelectedText.Value = "All") && Trim(EmployeeName) = Trim(User().FullName)
)),
(Dropdown4.SelectedText.Value = "All"),
(Filter(
TicketCollection,
(TaskStatus = TaskStatusDropdown_2.SelectedText.Value || TaskStatusDropdown_2.SelectedText.Value = "All") && (Trim(EmployeeName) = Trim(User().FullName))
)),
(Dropdown4.SelectedText.Value = "Last 3 months"),
(Filter(
TicketCollection,
Year(Now()),
Month(
DateValue(
Text(
DateValue(
NotStartedDate,
"fr"
),
"[$-en-US]mm/dd/yyyy"
)
)
) = DateAdd(Now(),-3,Months) || (Month(
DateValue(
Text(
DateValue(
NotStartedDate,
"fr"
),
"[$-en-US]mm/dd/yyyy"
)
)
) = DateAdd(Now(),-2,Months)) || (Month(
DateValue(
Text(
DateValue(
NotStartedDate,
"fr"
),
"[$-en-US]mm/dd/yyyy"
)
)
) = DateAdd(Now(),-1,Months)) && (TaskStatus = TaskStatusDropdown_2.SelectedText.Value || TaskStatusDropdown_2.SelectedText.Value = "All") && Trim(EmployeeName) = Trim(User().FullName)
)),
(Dropdown4.SelectedText.Value = "Last Week"),
(Filter(
TicketCollection,
DateDiff(
DateValue(
Text(
DateValue(
NotStartedDate,
"fr"
),
"[$-en-US]mm/dd/yyyy"
)
),
Today(),
Days
) < 7 && (TaskStatus = TaskStatusDropdown_2.SelectedText.Value || TaskStatusDropdown_2.SelectedText.Value = "All") && Trim(EmployeeName) = Trim(User().FullName)
)),
(Dropdown4.SelectedText.Value = "Current Month"),
(Filter(
TicketCollection,
Month(
DateValue(
Text(
DateValue(
NotStartedDate,
"fr"
),
"[$-en-US]mm/dd/yyyy"
)
)
) = Month(Now()) && (TaskStatus = TaskStatusDropdown_2.SelectedText.Value || TaskStatusDropdown_2.SelectedText.Value = "All") && Trim(EmployeeName) = Trim(User().FullName)
)),
(Dropdown4.SelectedText.Value = "Current Year"),
(Filter(
TicketCollection,
Year(
DateValue(
Text(
DateValue(
NotStartedDate,
"fr"
),
"[$-en-US]mm/dd/yyyy"
)
)
) = Year(Now()) && (TaskStatus = TaskStatusDropdown_2.SelectedText.Value || TaskStatusDropdown_2.SelectedText.Value = "All") && Trim(EmployeeName) = Trim(User().FullName)
)),
(Dropdown4.SelectedText.Value = "Current Week"),
(Filter(
TicketCollection,
DateValue(
Text(
DateValue(
NotStartedDate,
"fr"
),
"[$-en-US]mm/dd/yyyy"
)
) >= DateAdd(
Today(),
1 - Weekday(
Today(),
StartOfWeek.Sunday
)
) && (TaskStatus = TaskStatusDropdown_2.SelectedText.Value || TaskStatusDropdown_2.SelectedText.Value = "All") && Trim(EmployeeName) = Trim(User().FullName)
))
),
Created,
Descending
)

1 ACCEPTED SOLUTION

Accepted Solutions
v-bofeng-msft
Community Support
Community Support

Hi @Eben98 :

Do you want to get the following values

The first and last day of last week (Monday-Sunday)

The first and last day of last month

The first and last day of the last three months

Please try these codes:

The first day of last week(Monday):

 

DateAdd(Now(),-6-Weekday(Today())+1,Days)

 

The last day of last week(Sunday):

 

DateAdd(Now(),-Weekday(Today())+1,Days)

 

The first day of last month:

 

Date(Year(DateAdd(Now(),-1,Months)),Month((DateAdd(Now(),-1,Months))),1)

 

The last day of last month:

 

DateAdd(Now(),-Day(Today()),Days)

 

 The first day of the last three months:

 

Date(Year(DateAdd(Now(),-1,Months)),Month((DateAdd(Now(),-3,Months))),1)

 

 The last day of the last three months:

 

DateAdd(Today(),-Day(Today()),Days)

 

111.JPG

Because the number of days in each month is different, and a cycle of 12 months, there is no way to simply add and subtract by month and days, so I used this cumbersome but relatively robust method for your reference.

Best Regards,

Bof

View solution in original post

1 REPLY 1
v-bofeng-msft
Community Support
Community Support

Hi @Eben98 :

Do you want to get the following values

The first and last day of last week (Monday-Sunday)

The first and last day of last month

The first and last day of the last three months

Please try these codes:

The first day of last week(Monday):

 

DateAdd(Now(),-6-Weekday(Today())+1,Days)

 

The last day of last week(Sunday):

 

DateAdd(Now(),-Weekday(Today())+1,Days)

 

The first day of last month:

 

Date(Year(DateAdd(Now(),-1,Months)),Month((DateAdd(Now(),-1,Months))),1)

 

The last day of last month:

 

DateAdd(Now(),-Day(Today()),Days)

 

 The first day of the last three months:

 

Date(Year(DateAdd(Now(),-1,Months)),Month((DateAdd(Now(),-3,Months))),1)

 

 The last day of the last three months:

 

DateAdd(Today(),-Day(Today()),Days)

 

111.JPG

Because the number of days in each month is different, and a cycle of 12 months, there is no way to simply add and subtract by month and days, so I used this cumbersome but relatively robust method for your reference.

Best Regards,

Bof

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

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