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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
DA_B
New Member

text to Number - try otherwise?

Hey,

 

i've got a little problem. I have a large data set (multiple collumns and rows) which is split in dates (TTMMJJJJ), text and real number cells.

I can easily change the date collums from text do date. But the rest ist mixed togehter. If i try to change the type i get Error's - if i use the "Json" Tool to. Ive already tried to work with an try otherwise formula but it wont change the type, all i get is the cell replaced with "Type".

Is there also a easy way to change multiple collums at once?

 

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @DA_B ,

 

In general, a column that mix numbers and text in Power Query cannot be defined as numeric types.

If it is easy to extract numbers in your column, you can try the following formula.

=Text.Combine(List.Select(Text.ToList([Column1]), each Text.Contains("0123456789", _)), "")

vstephenmsft_0-1685071250145.png

This formula works by converting the text in the column to a list of characters using the Text.ToList function, and then selecting only the characters that are numbers using the List.Select function and the Text.Contains function. The resulting list of numbers is then combined back into a single text string using the Text.Combine function.


Note that this formula will only extract numbers that are contiguous in the text string. If there are non-numeric characters between the numbers, they will be ignored. If you need to extract numbers that are separated by non-numeric characters, you will need to modify the formula accordingly.

 

Best Regards,

Stephen Tao

 

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

3 REPLIES 3
v-stephen-msft
Community Support
Community Support

Hi @DA_B ,

 

In general, a column that mix numbers and text in Power Query cannot be defined as numeric types.

If it is easy to extract numbers in your column, you can try the following formula.

=Text.Combine(List.Select(Text.ToList([Column1]), each Text.Contains("0123456789", _)), "")

vstephenmsft_0-1685071250145.png

This formula works by converting the text in the column to a list of characters using the Text.ToList function, and then selecting only the characters that are numbers using the List.Select function and the Text.Contains function. The resulting list of numbers is then combined back into a single text string using the Text.Combine function.


Note that this formula will only extract numbers that are contiguous in the text string. If there are non-numeric characters between the numbers, they will be ignored. If you need to extract numbers that are separated by non-numeric characters, you will need to modify the formula accordingly.

 

Best Regards,

Stephen Tao

 

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

Hi @v-stephen-msft and @BA_Pete,

 

thank you guys for your Input. I've made a mini version of my data set i had to import into excel. It looked like:

 

100
"test1","test2","test3"
"31.12.2020","1","1.9"
"31.12.2021","1.5","1"
"31.12.2022","0","1"
"31.12.2023","x","0.3"
"31.12.2024","0","0"
"31.12.2025","y","0"
"31.12.2026","0","0"
"31.12.2027","1.1","y"
"31.12.2028","0","y"
"31.12.2029","1","x"

"end"
reanwf2r1p
qnpf

 

Just imagine it like 250k times 200 instead of 15 times 3.

 

My solution was quite simple: I've switches excel to the english version and imported the data (outside of Power Query). After that i simply changed it back to european (, instead of .) and i was done. 

Now everything is type standard and works accordingly.

 

Thank you for your time and effort.

 

Best Regards,

Daniel

BA_Pete
Super User
Super User

Hi @DA_B ,

 

You'll need to provide some copyable example data and what your expected output looks like please.

You can either paste directly from Excel into a post, or copy/paste the M code from an 'Enter Data' query.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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

Top Solution Authors