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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Moniek
Resolver I
Resolver I

Add column with a total based on 2 other columns

Hi,

 

I have a data table, I want to add a new column the "wish" column. In excel I know how to do, but how can I do it in Power Query to add the wish column? Additional info is in the image.

 

Moniek_0-1682346720449.png

Thanks

1 ACCEPTED SOLUTION
m_dekorte
Super User
Super User

Hi @Moniek ,

 

You could use Group By on the key columns you identified, that will return unique combinations. With some additional M code to extract the first value and repeat 0 for additional rows.

Copy this script into a new blank query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfIvSkktUgCxHIHYF4gNDYBAKVYnWskIQ94PRd4YLg9S6QTEAUBsZAqVNoFLgxQ6A3EgEBuDdccCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Index = _t, Order = _t, Type = _t, Label = _t, Amount = _t]),
    AddColumn = Table.Group(Source, {"Order", "Type"}, 
        {
            {"t", each Table.FromColumns( Table.ToColumns(_) & { {[Amount]{0}} & List.Repeat({0}, List.Count([Amount])-1)}, Table.ColumnNames(_) & {"Wish"}  ) }
        }
    )[[t]],
    ExpandTable = Table.ExpandTableColumn(AddColumn, "t", {"Index", "Order", "Type", "Label", "Amount", "Wish"})
in
    ExpandTable

 

 If you want to transfer this into your own code replace "Source" here

AddColumn = Table.Group(Source

 

With the previous step name in your query and you should be good to go.

Ps. Please mark this answer as solution when it helped you to resolve your question, thanks!

View solution in original post

1 REPLY 1
m_dekorte
Super User
Super User

Hi @Moniek ,

 

You could use Group By on the key columns you identified, that will return unique combinations. With some additional M code to extract the first value and repeat 0 for additional rows.

Copy this script into a new blank query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfIvSkktUgCxHIHYF4gNDYBAKVYnWskIQ94PRd4YLg9S6QTEAUBsZAqVNoFLgxQ6A3EgEBuDdccCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Index = _t, Order = _t, Type = _t, Label = _t, Amount = _t]),
    AddColumn = Table.Group(Source, {"Order", "Type"}, 
        {
            {"t", each Table.FromColumns( Table.ToColumns(_) & { {[Amount]{0}} & List.Repeat({0}, List.Count([Amount])-1)}, Table.ColumnNames(_) & {"Wish"}  ) }
        }
    )[[t]],
    ExpandTable = Table.ExpandTableColumn(AddColumn, "t", {"Index", "Order", "Type", "Label", "Amount", "Wish"})
in
    ExpandTable

 

 If you want to transfer this into your own code replace "Source" here

AddColumn = Table.Group(Source

 

With the previous step name in your query and you should be good to go.

Ps. Please mark this answer as solution when it helped you to resolve your question, thanks!

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors