cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
IDBdesign
Level: Powered On

Filter by Week using Date Column on Large SQL Table

Hello,

 

I have a fairly large direct-connection SQL table (>2000 rows) and I'm trying to pull rows from timespans of this week, last week, and this month.  What would be the correct way to do this?

 

I was going to try to use the Filter() function and use "< >=" to filter the Date column but I'm getting a delegation warning.  I know I can get around this by pulling unfiltered rows from the table, assigning them to a variable, and filtering the variable; however, with that method I would not be able to look very far back as even 2000 records would only reach back 4 days.

Any help would be greatly appreciated!

 

Thanks,

Isaac

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Filter by Week using Date Column on Large SQL Table

HI @IDBdesign ,

Do you want to filter your SQL Table records based on a timespans of this week, last week, and this month?

Could you please share a bit more about your Filter formula within your app?

 

I have made a test on my side, the Delegation warning shows up within my app. Actually, the Date time type column of SQL Table could not be delegated within Filter function in PowerApps currently. Please check the following article for more details:

https://docs.microsoft.com/en-us/connectors/sql/#powerapps-delegable-functions-and-operations-for-sq...

As an alternative solution, you could consider take a try to create a calculated column in your SQL Table based on your date time column using following SQL Syntax (check above article I mentioned):

ALTER TABLE myTable ADD DateAsInt AS (YEAR([YourDateColumn]) * 10000 + MONTH([YourDateColumn]) * 100 + DAY([YouDateColumn]))

then you could filter your SQL Table records based on this Calculated Number column instead of Date type column.

 

I assume that you have added a Calculated number column (DateAsInt) in your SQL Table based on above alternative solution, please take a try with the following workaround to achieve your needs:

1. Filter your SQL Table records from this week:

Filter(
        '[dbo].[YourSQLTable]',
        DateAsInt > Year(DateAdd(Now(), -Weekday(Now())+1)) * 10000 + Month(DateAdd(Now(), -Weekday(Now())+1)) * 100 + Day(DateAdd(Now(), -Weekday(Now())+1)) && DateAsInt < YEAR(DateAdd(Now(), 7-Weekday(Now()))) * 10000 + MONTH(DateAdd(Now(), 7-Weekday(Now()))) * 100 + DAY(DateAdd(Now(), 7-Weekday(Now())))
)

2. Filter your SQL Table reocrds from last week:

Filter(
        '[dbo].[YourSQLTable]',
        DateAsInt > Year(DateAdd(Now(), -Weekday(Now())+1-7)) * 10000 + Month(DateAdd(Now(), -Weekday(Now())+1-7)) * 100 + Day(DateAdd(Now(), -Weekday(Now())+1-7)) && DateAsInt < YEAR(DateAdd(Now(), 7-Weekday(Now())-7)) * 10000 + MONTH(DateAdd(Now(), 7-Weekday(Now())-7)) * 100 + DAY(DateAdd(Now(), 7-Weekday(Now())-7))
)

3. Filter your SQL Table records from this month:

Filter(
        '[dbo].[YourSQLTable]',
        DateAsInt > Year(DateAdd(Now(),-Day(Now())+1)) * 10000 + Month(DateAdd(Now(),-Day(Now())+1)) * 100 + Day(DateAdd(Now(),-Day(Now())+1)) && DateAsInt < YEAR(DateAdd(DateAdd(Now(),1,Months),-Day(DateAdd(Now(),1,Months)))) * 10000 + MONTH(DateAdd(DateAdd(Now(),1,Months),-Day(DateAdd(Now(),1,Months)))) * 100 + DAY(DateAdd(DateAdd(Now(),1,Months),-Day(DateAdd(Now(),1,Months))))
)

Please take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
1 REPLY 1
Community Support Team
Community Support Team

Re: Filter by Week using Date Column on Large SQL Table

HI @IDBdesign ,

Do you want to filter your SQL Table records based on a timespans of this week, last week, and this month?

Could you please share a bit more about your Filter formula within your app?

 

I have made a test on my side, the Delegation warning shows up within my app. Actually, the Date time type column of SQL Table could not be delegated within Filter function in PowerApps currently. Please check the following article for more details:

https://docs.microsoft.com/en-us/connectors/sql/#powerapps-delegable-functions-and-operations-for-sq...

As an alternative solution, you could consider take a try to create a calculated column in your SQL Table based on your date time column using following SQL Syntax (check above article I mentioned):

ALTER TABLE myTable ADD DateAsInt AS (YEAR([YourDateColumn]) * 10000 + MONTH([YourDateColumn]) * 100 + DAY([YouDateColumn]))

then you could filter your SQL Table records based on this Calculated Number column instead of Date type column.

 

I assume that you have added a Calculated number column (DateAsInt) in your SQL Table based on above alternative solution, please take a try with the following workaround to achieve your needs:

1. Filter your SQL Table records from this week:

Filter(
        '[dbo].[YourSQLTable]',
        DateAsInt > Year(DateAdd(Now(), -Weekday(Now())+1)) * 10000 + Month(DateAdd(Now(), -Weekday(Now())+1)) * 100 + Day(DateAdd(Now(), -Weekday(Now())+1)) && DateAsInt < YEAR(DateAdd(Now(), 7-Weekday(Now()))) * 10000 + MONTH(DateAdd(Now(), 7-Weekday(Now()))) * 100 + DAY(DateAdd(Now(), 7-Weekday(Now())))
)

2. Filter your SQL Table reocrds from last week:

Filter(
        '[dbo].[YourSQLTable]',
        DateAsInt > Year(DateAdd(Now(), -Weekday(Now())+1-7)) * 10000 + Month(DateAdd(Now(), -Weekday(Now())+1-7)) * 100 + Day(DateAdd(Now(), -Weekday(Now())+1-7)) && DateAsInt < YEAR(DateAdd(Now(), 7-Weekday(Now())-7)) * 10000 + MONTH(DateAdd(Now(), 7-Weekday(Now())-7)) * 100 + DAY(DateAdd(Now(), 7-Weekday(Now())-7))
)

3. Filter your SQL Table records from this month:

Filter(
        '[dbo].[YourSQLTable]',
        DateAsInt > Year(DateAdd(Now(),-Day(Now())+1)) * 10000 + Month(DateAdd(Now(),-Day(Now())+1)) * 100 + Day(DateAdd(Now(),-Day(Now())+1)) && DateAsInt < YEAR(DateAdd(DateAdd(Now(),1,Months),-Day(DateAdd(Now(),1,Months)))) * 10000 + MONTH(DateAdd(DateAdd(Now(),1,Months),-Day(DateAdd(Now(),1,Months)))) * 100 + DAY(DateAdd(DateAdd(Now(),1,Months),-Day(DateAdd(Now(),1,Months))))
)

Please take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Users Online
Currently online: 182 members 5,094 guests
Please welcome our newest community members: