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
cgkas
Helper V
Helper V

How to add a custom column with specific text in each row?

Hello to all,

 

The syntax to represent a list is list1 = {"A", "B","C"}. Is there a way to represent a column in hardcoded way like a list?

 

I have a table with 3 rows and I want to add a custom column with the values Yellow, Blue and White. I'm doing like below

 

= Table.AddColumn(#"Added Custom", "Custom", each Table.FromList({"Yellow","Blue", "White"}))

 But this code adds the column "Custom" with each element containing a table. 

 

How can I create the new column with row1 = "Yellow", row2="Blue", row3="White"?

 

Thanks for any help

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @cgkas ,

Can this meet your requirements?

add custom column.gif

 

Attach the complete codes:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKsovN1SK1QEzjGAMYxjDBMYwhTHMlGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Mod", each Number.Mod([Index],3)),
    #"Added Conditional Column" = Table.AddColumn(#"Added Custom", "Color", each if [Mod] = 1 then "Yellow" else if [Mod] = 2 then "Blue" else if [Mod] = 0 then "White" else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"Index", "Mod"})
in
    #"Removed Columns"

 

Best Regards,

Icey

 

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

5 REPLIES 5
Icey
Community Support
Community Support

Hi @cgkas ,

Can this meet your requirements?

add custom column.gif

 

Attach the complete codes:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKsovN1SK1QEzjGAMYxjDBMYwhTHMlGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Mod", each Number.Mod([Index],3)),
    #"Added Conditional Column" = Table.AddColumn(#"Added Custom", "Color", each if [Mod] = 1 then "Yellow" else if [Mod] = 2 then "Blue" else if [Mod] = 0 then "White" else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"Index", "Mod"})
in
    #"Removed Columns"

 

Best Regards,

Icey

 

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

 

 

Thanks @Icey and @kentyler for answer.

 

Thanks @Icey for the solution shared. I think I could apply your logic to my case.

 

Regards

kentyler
Solution Sage
Solution Sage

Have you considered using "Merge Columns".  First create a small table with one column with the values you want in each row. Then merge it with the table you want to add the column to.





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Hello @kentyler ,

 

I've tried like you suggested, but I think something is missing.

 

I have the following steps:

 

First step:       Source (This is the table with several columns for which I want to add the new column)

Second step:  SmallTable (The small table you suggested)

Third step:     MergeColumn

 

The merge column step has this command, but I get error.

= Table.AddColumn(Source, "Merged", each Text.Combine({[NewColHearder]}, ""), type text)

 

May you show please how should be used the merge in this case.

 

Thanks 

Power BI is not really a data entry program. You cannot merge tables unless they each have a column that can be used to relate them to each other.
You are probably using a simplified example. 

Why are you trying to do this.
Why not just add the new column in your data source.
If the colors you want to add is related to the other columns, for example, each color represents a city, then you need a custom column with some DAX code in it to pick the color for the row.
If you want to to a screen share to explore this, send me your email ( ken@8thfold.com ). I suspect you are trying to use power bi to do something it cannot do and that you will have to do in your data source.





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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