Forum Discussion
credencial
4 years agoFrequent Visitor
Apportionment of values based ID
Hi,
I have a table:
I would like to take the first value of ID and prorate between the same IDs. Thus:
| ID | DESCONTO | FRETE |
| 1 | 6,66 | 0 |
| 1 | 6,66 | 0 |
| 1 | 6,66 | 0 |
| 2 | 0 | 3,42 |
| 2 | 0 | 3,42 |
| 2 | 0 | 3,42 |
| 2 | 0 | 3,42 |
Thanks for your any help.
credencial try this
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIyABIGSrE6hLhGYJaOkqGxnpkFuSKxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [id = _t, val1 = _t, val2 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"val1", Int64.Type}, {"val2", type number}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"id"}, {{"ar", each _, type table [id=nullable number, val1=nullable number, val2=nullable number]}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "val1", each let x =[ar], y =x[val1], y1= List.Count(y), z = List.Repeat({List.Distinct(y){0}/y1},y1) in z), #"Added Custom1" = Table.AddColumn(#"Added Custom", "val2", each let x =[ar], y =x[val2], y1= List.Count(y), z = List.Repeat({List.Distinct(y){0}/y1},y1) in z), #"Removed Columns1" = Table.RemoveColumns(#"Added Custom1",{"ar"}), #"Added Custom2" = Table.AddColumn(#"Removed Columns1", "Custom", each Table.FromColumns({[val1],[val2]})), #"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"val1", "val2"}), #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Column1", "Column2"}, {"Column1", "Column2"}) in #"Expanded Custom"
1 Reply
- smpa01Community Champion
credencial try this
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIyABIGSrE6hLhGYJaOkqGxnpkFuSKxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [id = _t, val1 = _t, val2 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"val1", Int64.Type}, {"val2", type number}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"id"}, {{"ar", each _, type table [id=nullable number, val1=nullable number, val2=nullable number]}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "val1", each let x =[ar], y =x[val1], y1= List.Count(y), z = List.Repeat({List.Distinct(y){0}/y1},y1) in z), #"Added Custom1" = Table.AddColumn(#"Added Custom", "val2", each let x =[ar], y =x[val2], y1= List.Count(y), z = List.Repeat({List.Distinct(y){0}/y1},y1) in z), #"Removed Columns1" = Table.RemoveColumns(#"Added Custom1",{"ar"}), #"Added Custom2" = Table.AddColumn(#"Removed Columns1", "Custom", each Table.FromColumns({[val1],[val2]})), #"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"val1", "val2"}), #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Column1", "Column2"}, {"Column1", "Column2"}) in #"Expanded Custom"