cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Memorable Member
Memorable Member

Re: Convert Column from Text to Number in Direct Query

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

6 REPLIES 6
Highlighted
Memorable Member
Memorable Member

Re: Convert Column from Text to Number in Direct Query

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

Highlighted
Resident Rockstar
Resident Rockstar

Re: Convert Column from Text to Number in Direct Query

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.
Highlighted
Resolver I
Resolver I

Re: Convert Column from Text to Number in Direct Query

@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 

Highlighted
Memorable Member
Memorable Member

Re: Convert Column from Text to Number in Direct Query

@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!

Highlighted
Resolver I
Resolver I

Re: Convert Column from Text to Number in Direct Query

Perfect. Thank you!

Highlighted
Helper II
Helper II

Re: Convert Column from Text to Number in Direct Query

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 ?

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors