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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
SBC
Helper III
Helper III

How to change data type text to date direct query mode

Hi ,

 DirectQuery mode in PowerBI, can we change data type of a column  from text to date ?

Example:

i have column which contains all dates in text data type,i want to change to date data type in the report.

 

Metaparttionvalue

2022/07/21

2022/07/22

2022/08/02

.........................

below is the error while changing data type from text  to date

error:

 

SBC_0-1659684326706.png

 

 

1 ACCEPTED SOLUTION
Bubble4502
Resolver III
Resolver III

Hi @SBC ,

 

DirectQuery has limitations in the data transformations that can be applied within Power Query Editor.

First, when connecting to an OLAP source like SAP Business Warehouse, no transformations can be defined at all, and the entire external model is taken from the source. For relational sources, like SQL Server, it's still possible to define a set of transformations per query, but those transformations are limited for performance reasons.

Any such transformation will need to be applied on every query to the underlying source, rather than once on data refresh, so they're limited to those transformations that can reasonably be translated into a single native query. If you use a transformation that is too complex, you receive an error that either it must be deleted or the model switched to import.

 

You can create a measure to replace the date column

Here is an example:

Bubble4502_1-1660120750022.png

Here is the measure:

Measure = 
var _y = VALUE(LEFT(MAX('Table'[Column]),4))
var _m = VALUE(LEFT(RIGHT(MAX('Table'[Column]),5),2))
var _d = VALUE(RIGHT(MAX('Table'[Column]),2))
return DATE(_y,_m,_d)

Then change the format of the measure:

Bubble4502_2-1660121077381.png

Final output:

Bubble4502_3-1660121096517.png

 

Kind Regards,

Bubble

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

6 REPLIES 6
Apayo
New Member

Hi! I have the same problem in DirectQuery but from text to numeric.

 

Apayo_0-1705920955584.png

As can be seen, I have some scores as text and I want to convert them to numeric so I can make aggregations. I am getting the following error:

Apayo_1-1705921065330.png

Thanks!

@Bubble4502 

Bubble4502
Resolver III
Resolver III

Hi @SBC ,

 

DirectQuery has limitations in the data transformations that can be applied within Power Query Editor.

First, when connecting to an OLAP source like SAP Business Warehouse, no transformations can be defined at all, and the entire external model is taken from the source. For relational sources, like SQL Server, it's still possible to define a set of transformations per query, but those transformations are limited for performance reasons.

Any such transformation will need to be applied on every query to the underlying source, rather than once on data refresh, so they're limited to those transformations that can reasonably be translated into a single native query. If you use a transformation that is too complex, you receive an error that either it must be deleted or the model switched to import.

 

You can create a measure to replace the date column

Here is an example:

Bubble4502_1-1660120750022.png

Here is the measure:

Measure = 
var _y = VALUE(LEFT(MAX('Table'[Column]),4))
var _m = VALUE(LEFT(RIGHT(MAX('Table'[Column]),5),2))
var _d = VALUE(RIGHT(MAX('Table'[Column]),2))
return DATE(_y,_m,_d)

Then change the format of the measure:

Bubble4502_2-1660121077381.png

Final output:

Bubble4502_3-1660121096517.png

 

Kind Regards,

Bubble

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

I have used same formula but I am getting same value for all the columns and that is with wrong date value.

Could you please tell me how I can solve this.

IMG_20240311_234819.jpg

IMG_20240311_231233_267.jpg

  

 

 

Anonymous
Not applicable

I want to ask why do we need to use the MAX function, when I applied the same function on my table, my new column show the latest date of the [Column] , instead of converting the text on the left side.  However, when I remove MAX function, it doesn't work, and it showed error as Direct Query doesn't support DATE function.  Any solution ??? Thanks.

The limitation of a date measure is that you can't use it in a date slicer or in a relationship with the date table. If possible, use the SQL functions CAST or CONVERT, which will enable you to have a date column (as opposed to a measure).





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




DataInsights
Super User
Super User

@SBC,

 

Have you tried custom SQL using the CAST or CONVERT functions?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.