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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Andreaal
New Member

Combined text and number data in one single column

Does anyone know how to change the data type of a column from text to "Text and number"?

 

I have a SAP Report that I have already uploaded to my Power Query and a column that contains IDs in both number and text+number formats, in this table the ID column is directly imported as text in Power BI. Example:

Table1

IDSales Qty
2100.10100
ADF-G7615200
3100.10300
4100.20400

 

And I have another Excel data table with my "master data" that contains the same ID column, but when I import this excel table, Power BI automatically displays the column type as: text and number (123ABC) 

Table2

IDDemand Qty
2100.1110
ADF-G7615200
3100.1300
4100.2450

 

The problem is that Table1 is as text and the ID is represented as example: 2100.10 and in Table2 as decimal number 2100.1 - so it  eliminates the zero at the end, therefore when I try to relate the columns, it displays error. 

 

* I tried changing the column in my Excel File to text format to make sure I have the zeros, but when I upload it to the Power Query it still changes the data type to 123ABC and the zeros disappear.

* I tried changing the data type to text but it still does not display the zeros. 

* I also tried changing Table1 to number type but displays error for the IDs that combine text+number.

 

Can anybody help me figure out a way to make sure both columns contain the same values? 

 

Thank you very much

1 ACCEPTED SOLUTION
tackytechtom
Super User
Super User

Hi @Andreaal ,

 

If I understand your query correctly, you would like to add back the 0. How about this:

 

Before:

tomfox_0-1661888081009.png

 

 

After:

tomfox_1-1661888098088.png

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI0MNAzVNJRMjQ0UIrViVZydHHTdTc3MzQFihkZQMSMYYqMoQImIAEjoICJKVAgFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Demand Qty" = _t]),
    #"Replace Values" = Table.ReplaceValue(Source, each [ID], each try Number.ToText ( Number.From([ID]), "f" ) otherwise [ID], Replacer.ReplaceValue,{"ID"})

in
    #"Replace Values"

 

Let me know, if this solves your issue 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

1 REPLY 1
tackytechtom
Super User
Super User

Hi @Andreaal ,

 

If I understand your query correctly, you would like to add back the 0. How about this:

 

Before:

tomfox_0-1661888081009.png

 

 

After:

tomfox_1-1661888098088.png

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI0MNAzVNJRMjQ0UIrViVZydHHTdTc3MzQFihkZQMSMYYqMoQImIAEjoICJKVAgFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Demand Qty" = _t]),
    #"Replace Values" = Table.ReplaceValue(Source, each [ID], each try Number.ToText ( Number.From([ID]), "f" ) otherwise [ID], Replacer.ReplaceValue,{"ID"})

in
    #"Replace Values"

 

Let me know, if this solves your issue 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

Top Solution Authors
Top Kudoed Authors