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
Gertjan
Frequent Visitor

Change date type without losing native query

Hi there,

 

I have a table with two columns: item and date. There are four applied steps in the Power Query: Source, Navigation, Renamed Columns and Changed Type. 

Date is initially formatted as text, but I want it to be a date, so that's what the Changed Type step is all about. However, I lose native query after adding this step. Is there a way to avoid this, so that it will still be possible to view native query? 

 

I don't want to change the date type already in the SQL database (because of multiple databases with several languages).

Any kind of help is appreciated. Thanks!

Gertjan_0-1655725475618.png

 

7 REPLIES 7
v-kkf-msft
Community Support
Community Support

Hi @Gertjan ,

 

In Power Query, Text -> all transformations would break query-folding.

Changing data types that do not break query-folding in Power Query / Power BI 

 

Please try using sql statement in query.

 

let
    Source = Sql.Database(".", "CaseTest", [Query="select #(lf)    CAST( [Date2] AS date) [Date],#(lf)    [Value] as [Rename_Value]#(lf)from [dbo].[Test1$]"])
in
    Source

vkkfmsft_0-1655966627344.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for your suggestion. However, it still doesn't allow me to view native query.

Gertjan_0-1655971908787.png

Maybe it's just not possible?

watkinnc
Super User
Super User

That is surprising, my friend.  Did you happen to re-click the steps from beginning to end, to make sure that the View Native Query doesn't light up?  Or perhaps clear the cache?

 

Oh yeah, you could try Date.FromText, or even just the Parse Date GUI function.

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

I re-clicked the steps, cleared the cache and tried the other functions. However, View Native Query still doesn't light up. Any other ideas?

watkinnc
Super User
Super User

Instead of Table.TransformColumnTypes, go back and make it Table.TransformColumns, and replace "type date" with "Date.From". Basically using Date.From to transform instead of changing types.

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

Thanks @watkinnc, the query itself works, however it still doesn't allow to view native query. Any other solution?

Gertjan_0-1655732714066.png

Gertjan_1-1655732771751.png

 

 

Not sure if you still searching for a fix, however this is how i did it.

 

Use this in the SQL statement " CONVERT(DATE, t.[SHIPDATE], 103) AS 'Shipment Date'  " (use your column names )

 

It will automatically recognise the column as Date/Time 

AlexCod_0-1700566892959.png

 

And you do not need the "Changed Type" step that blocks the Native Query: 

AlexCod_1-1700566932227.png

 

And after that, just change the format to "Short Date" from the "Table View"

AlexCod_2-1700567026495.png

 

And you can use the column in a relashionship with another table.

AlexCod_3-1700567098832.png

 

 

And because you are not breaking the Native Query, you can use the "Incremental Refresh" as well without the warning of not being able to fold.

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