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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
925stuart
Helper I
Helper I

Which function should I use to convert text to number in a new column?

Hi,

 

Which function should I use to convert text to number in a new column?  I want to convert these:-

 

Chocolate = 1

Candy = 2

Bottled Water = 3

Beer = 4

 

Thanks!

1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

Hi, @925stuart I hope you've got the idea. 

let
    Source = #table({"product"}, {{"Chocolate"}, {"Candy"}, {"Bottled Water"}, {"Beer"}}),
    rec = [Chocolate = 1, Candy = 2, Bottled Water = 3, Beer = 4],
    new_column = Table.AddColumn(Source, "new_column", each Record.FieldOrDefault(rec, [product]))
in
    new_column

 

View solution in original post

2 REPLIES 2
925stuart
Helper I
Helper I

Cool!  That was what I needed to get started!  Found the doc!

AlienSx
Super User
Super User

Hi, @925stuart I hope you've got the idea. 

let
    Source = #table({"product"}, {{"Chocolate"}, {"Candy"}, {"Bottled Water"}, {"Beer"}}),
    rec = [Chocolate = 1, Candy = 2, Bottled Water = 3, Beer = 4],
    new_column = Table.AddColumn(Source, "new_column", each Record.FieldOrDefault(rec, [product]))
in
    new_column

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.