cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
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
Highlighted
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
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (9,697)