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
danb
Resolver I
Resolver I

Convert Column from Text to Number in Direct Query

Hi Experts! 

I am running into an issue around trying to convert a column that is connected via direct query from a database from "Text" to "Number" type. I know that the proper way to do this is to make the adjustment in the database itself however I was wondering if there was an alternate way to do this in the query editor without having to switch everything to an Import? 

 

Thanks

 

Dan 

2 ACCEPTED SOLUTIONS
zoloturu
Memorable Member
Memorable Member

Hi @danb,

 

What if while connecting to a database using DirectQuery you will use NativeQuery, where you can do whatever you want?

See example with CAST(CONVERT) below:

 

DQ castDQ cast

Regards,
Ruslan
-------------------------------------------------------------------
Did I answer your question? Mark my post as a solution!

View solution in original post

zoloturu
Memorable Member
Memorable Member

@danb,

 

it acts as a SQL batch (syntax is unlimited). So if you enter a query as I mentioned then it will be send to the database (calculations done on db side) and a result will be returned to Power BI. Use just SELECT statement and you will be safe. 

 

Regards,
Ruslan
-------------------------------------------------------------------
Did I answer your question? Mark my post as a solution!

View solution in original post

8 REPLIES 8
GorkemT
New Member

Hello there,

 

I have the same exact problem with the dataverse tables not with SQL. So is there a solution for dataverse too? I would like to change the data type from text to whole number or decimal, does not matter at all. the thing is i do not want to loose the direct query from db. 

 

thank you

v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @danb,

 

By my tests, the solution from zoloturu could solve your problem.

 

If you have solved your problem, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
zoloturu
Memorable Member
Memorable Member

Hi @danb,

 

What if while connecting to a database using DirectQuery you will use NativeQuery, where you can do whatever you want?

See example with CAST(CONVERT) below:

 

DQ castDQ cast

Regards,
Ruslan
-------------------------------------------------------------------
Did I answer your question? Mark my post as a solution!

@zoloturu

Thank you for your reply. So with the Cast/Convert, does that make changes to the actual database or just modify the the data as it is queried into Power BI?

 

Dan 

zoloturu
Memorable Member
Memorable Member

@danb,

 

it acts as a SQL batch (syntax is unlimited). So if you enter a query as I mentioned then it will be send to the database (calculations done on db side) and a result will be returned to Power BI. Use just SELECT statement and you will be safe. 

 

Regards,
Ruslan
-------------------------------------------------------------------
Did I answer your question? Mark my post as a solution!

Hello there,

 

I am having the same issue but your solution didn't work....

 

CAST(KPR_ptpi_amount as int) as (KPRAmount),

 

The error i get is:

DataSource.Error: Microsoft SQL: Incorrect syntax near '('.
Details:
    DataSourceKind=SQL
    DataSourcePath=rsobdcgenf;credopsreports
    Message=Incorrect syntax near '('.
    Number=102
    Class=15

 

What could i be doing wrong ?

There should be no parantheses (brackets) around your "(KPRAmount)" I think...

 

3 years late, but I'm here to save you!

Perfect. Thank you!

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.