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

Filter Date in SQL

Hi all,

 

if just want to filter my gallery on a date field. Something like:

 

SortByColumns(    
         Filter('[dbo].[tTime]'; Date=Text(_dateSelected; "[$-de-DE]yyyy-mm-dd") & " 00:00:00.000")
; "Date")

But it doesn't work.

I'm using the CalendarScreen for my example:

 

1.PNG

Here's a screenshot of my database table (field "date"):

 

2.PNG

Can you help me please?

 

thanks

jup

1 ACCEPTED SOLUTION

Accepted Solutions
Dual Super User
Dual Super User

Re: Filter Date in SQL

From the documentation on SQL delegation limitations

 

Direct date filters do not work for SQL Server. However, you can create a calculated column that will work. For instance, ALTER TABLE myTable ADD DateAsInt AS (YEAR([date]) * 10000 + MONTH([date]) * 100 + DAY([date])) and then filter on the calculated number column.

 

To filter on the date with delegation you'll need to add a calculated column to your SQL Table.

The other possibility that might also work would be to do your Filter statement at two levels like this:

Filter(Filter('[dbo].[tZeit]';PersonalNr=1513),Text(Datum;"[$-de-DE]yyy-mm-dd")="2017-01-71")

This will work even though the Date filter isn't delegable IF the filter on PersonalNr can get the record set below 500 records returned. So this strategy depends on your data.

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

6 REPLIES 6
Dual Super User
Dual Super User

Re: Filter Date in SQL

Put a Text() formatting function around the Date field also so both sides of the equation are considered text.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
jup
Level: Powered On

Re: Filter Date in SQL

No. Sorry. Doesn't work:

 

Filter('[dbo].[tZeit]'; Text(Datum)="2017-05-01 00:00:00.000")

 

Doesn' t work,too:

 

Filter('[dbo].[tZeit]'; Text(Datum;"[$-de-DE]")="2017-05-01 00:00:00.000")

jup
Level: Powered On

Re: Filter Date in SQL

any idea?

Highlighted
jup
Level: Powered On

Re: Filter Date in SQL

I got (a little bit)...

but other question:

 

If I use this formula - it works great:

1.PNGI get the results of my formula 🙂

 

BUT if I want to use a 2nd filter condition, the formula will be underlined blue and I'll get no results (because of "Delegation limit"):

2.PNG

 

How can I solve this problem?

 

Thanks,

jup

Dual Super User
Dual Super User

Re: Filter Date in SQL

Hi @jup 

 

Can you please try to modify your expression as:
 
SortByColumns(   
         Filter('[dbo].[tTime]'; DateValue(Text(Date))=DateValue(Text(_dateSelected; "[$-de-DE]yyyy-mm-dd")))
; "Date")
Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
Dual Super User
Dual Super User

Re: Filter Date in SQL

From the documentation on SQL delegation limitations

 

Direct date filters do not work for SQL Server. However, you can create a calculated column that will work. For instance, ALTER TABLE myTable ADD DateAsInt AS (YEAR([date]) * 10000 + MONTH([date]) * 100 + DAY([date])) and then filter on the calculated number column.

 

To filter on the date with delegation you'll need to add a calculated column to your SQL Table.

The other possibility that might also work would be to do your Filter statement at two levels like this:

Filter(Filter('[dbo].[tZeit]';PersonalNr=1513),Text(Datum;"[$-de-DE]yyy-mm-dd")="2017-01-71")

This will work even though the Date filter isn't delegable IF the filter on PersonalNr can get the record set below 500 records returned. So this strategy depends on your data.

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Helpful resources

Announcements
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

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