Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

filter by date without losing query folding

Hi all, 

 

I am using the HANA connector in import-mode to import a table which has a date-column. I want to filter the query based on this date-column, however it's not formatted as dates. I could easily change the data type to date and then apply a filter based on the date range. However, by doing so I lose query folding, and from what I understood, it then imports all the dates before filtering, which is not what I want. 

 

The dates are stated as yyyymmdd. 

 

What are my possibilities? For instance I would like to import only the dates within current and last year, how would I go about that?

 

Thanks in advance!

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

Changing the data type of a column in Power Query Editor will break query folding, so please delete the "Changed type" step. Then you can try @Daryl-Lynch-Bzy 's suggestions. If your date column in the data source is in number data type, filtering will not break query folding. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi there. I don't know if this was indeed "solved", as the solutions I read here did not work for me, but I have found a way to at least filter the dates without breaking them (for now). I may still have to change the column data type to 'date' at the end in order for my report to work correctly. Still, filtering dates dramatically lowers the amount of data my query must process, so doing it early on is a huge advantage. This filter removes over 80% of the data from the query right off the top.

 

Pretty simple solution. Using the Filter Rows function, I am filtering down to text that begins with 2021, 2022, and 2023. This eliminates all of the years I did not want in my report while keeping the ones that did. Now, I can make the transformations I want across the rest of the query, and if absolutely necessary I can change the data to 'date' at the end. That way the query folding will not break until there's the least amount of data left possible. I hope this helps!

romatno_0-1674500528168.png

 

 

 

ppm1
Solution Sage
Solution Sage

If the dates are truly text (and not integer as suggested already), you may be able to dynamically generate the list of text date values and then use a List.Contains in your column filter. You could quickly find out if it folds with a hard-coded list of dates, before spending time on the dynamic part. Your filter step might look like this (change the Previous Step and DateTextColumn to match your query/data).

 

= Table.SelectRows(#"Previous Step", each List.Contains({"20220930", "20220929"}, [DateTextColumn]))

 

Pat

Microsoft Employee
v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

Changing the data type of a column in Power Query Editor will break query folding, so please delete the "Changed type" step. Then you can try @Daryl-Lynch-Bzy 's suggestions. If your date column in the data source is in number data type, filtering will not break query folding. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

 

Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @Anonymous - the value "yyyymmdd" is a date format, so do you mean that the data type of the column is not Date type.

If you are lucky, the data type might by INTERGER, so you can simply try INT > 20211230 and INT < 20220928.

If the data type is Text, this might still work TEXT > "20211230" and TEXT < "20220928".   Otherwise you may want try adding a new column which converts to INT.  See if it is still folding.  Then try to filter the new column.

If is Date Type, you may need to consider using Native Query to force folding to SAP Hana.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors