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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anildp
Helper II
Helper II

Calculations in same row data and create new table

Hi,

 

Need help with below situation

 

I have a table with the values as below 

 

this is the actual data 

 

DescriptionValue
Bucket 1100
Bucket 2300
Bucket 3400
Bucket 5 200

 

I would like to create a Row in this table with below calculation  / Separate table with all buckets ordered in sequence format. 

 

Bucket 4 = (Bucket 1 -(Bucket 2 + Bucket 3))

 

can someone help me on how to achieve this?

 

Thanks

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

Hi @Anildp 

Finally i can get this table

7.png

Write this code in Advanced editor (Homw->Queries Editor)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcipNzk4tUTBU0lEyNDBQitWBCxkBhYxRhYyBQiaoQqYKQDEjkFgsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Description = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Description", type text}, {"Value", Int64.Type}}),
    
    Source1 = #"Changed Type",
    #"Filtered Rows1" = Table.SelectRows(#"Changed Type", each ([Description] = "Bucket 1")),
    #"Filtered Rows2" = Table.SelectRows(#"Changed Type", each ([Description] = "Bucket 2")),
    #"Filtered Rows3" = Table.SelectRows(#"Changed Type", each ([Description] = "Bucket 3")),
   
    #"Added Custom1" = Table.AddColumn(#"Filtered Rows2", "Custom1", each #"Filtered Rows3" [Value]),
    #"Extracted Values1" = Table.TransformColumns(#"Added Custom1", {"Custom1", each Text.Combine(List.Transform(_, Text.From)), type text}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Extracted Values1",{{"Custom1", Int64.Type}}),
    #"Added Custom1.1" = Table.AddColumn(#"Changed Type1", "Custom1.1", each [Value]+[Custom1]),

    #"Added Custom2" = Table.AddColumn(#"Filtered Rows1", "Custom2", each #"Added Custom1.1"),
    #"Expanded Custom2" = Table.ExpandTableColumn(#"Added Custom2", "Custom2", {"Custom1.1"}, {"Custom.Custom1.1"}),
    #"Added Custom2.1" = Table.AddColumn(#"Expanded Custom2", "Custom2.1", each [Value]-[Custom.Custom1.1]),
    #"Removed Columns2" = Table.RemoveColumns(#"Added Custom2.1",{"Value", "Custom.Custom1.1"}),
    #"Renamed Columns2" = Table.RenameColumns(#"Removed Columns2",{{"Custom2.1", "Value"}}),
    #"Replaced Value2" = Table.ReplaceValue(#"Renamed Columns2","Bucket 1","Bucket 4",Replacer.ReplaceText,{"Description"}),
    
    #"Appended Query" = Table.Combine({#"Changed Type", #"Replaced Value2"}),
    #"Sorted Rows" = Table.Sort(#"Appended Query",{{"Description", Order.Ascending}})

in
    #"Sorted Rows"

Best Regards
Maggie

 

Community Support Team _ Maggie Li
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

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @Anildp 

Finally i can get this table

7.png

Write this code in Advanced editor (Homw->Queries Editor)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcipNzk4tUTBU0lEyNDBQitWBCxkBhYxRhYyBQiaoQqYKQDEjkFgsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Description = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Description", type text}, {"Value", Int64.Type}}),
    
    Source1 = #"Changed Type",
    #"Filtered Rows1" = Table.SelectRows(#"Changed Type", each ([Description] = "Bucket 1")),
    #"Filtered Rows2" = Table.SelectRows(#"Changed Type", each ([Description] = "Bucket 2")),
    #"Filtered Rows3" = Table.SelectRows(#"Changed Type", each ([Description] = "Bucket 3")),
   
    #"Added Custom1" = Table.AddColumn(#"Filtered Rows2", "Custom1", each #"Filtered Rows3" [Value]),
    #"Extracted Values1" = Table.TransformColumns(#"Added Custom1", {"Custom1", each Text.Combine(List.Transform(_, Text.From)), type text}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Extracted Values1",{{"Custom1", Int64.Type}}),
    #"Added Custom1.1" = Table.AddColumn(#"Changed Type1", "Custom1.1", each [Value]+[Custom1]),

    #"Added Custom2" = Table.AddColumn(#"Filtered Rows1", "Custom2", each #"Added Custom1.1"),
    #"Expanded Custom2" = Table.ExpandTableColumn(#"Added Custom2", "Custom2", {"Custom1.1"}, {"Custom.Custom1.1"}),
    #"Added Custom2.1" = Table.AddColumn(#"Expanded Custom2", "Custom2.1", each [Value]-[Custom.Custom1.1]),
    #"Removed Columns2" = Table.RemoveColumns(#"Added Custom2.1",{"Value", "Custom.Custom1.1"}),
    #"Renamed Columns2" = Table.RenameColumns(#"Removed Columns2",{{"Custom2.1", "Value"}}),
    #"Replaced Value2" = Table.ReplaceValue(#"Renamed Columns2","Bucket 1","Bucket 4",Replacer.ReplaceText,{"Description"}),
    
    #"Appended Query" = Table.Combine({#"Changed Type", #"Replaced Value2"}),
    #"Sorted Rows" = Table.Sort(#"Appended Query",{{"Description", Order.Ascending}})

in
    #"Sorted Rows"

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-juanli-msft  Thank you so much for the solution, it worked , thanks for helping me out.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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