cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jup
Helper II
Helper II

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
Pstork1
Dual Super User III
Dual Super User III

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
Pstork1
Dual Super User III
Dual Super User III

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.

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")

any idea?

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

yashag2255
Dual Super User II
Dual Super User II

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!
Pstork1
Dual Super User III
Dual Super User III

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
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,627)