Forum Discussion
Power BI Desktop query
- 2 years ago
You can do this in Power Query.
Group the the table with the types by name choosing all rows to get a nested table per name.
Merge by Name with the money query.
Expand the merge to get the money column
Add a column to get the row count of the nested tables.
Table.AddColumn(PREVIOUSSTEP, "nestedRowCount", each Table.RowCount([_nestedTable]), Int64.Type)Replace the values in the money column with the money value divided by the nested row count.
Table.ReplaceValue(PREVIOUSSTEP,each [money],each [money]/[nestedRowCount],Replacer.ReplaceValue,{"money"})Remove the nestedRowCount column
expand the nested table type column only.
You should get something like...
- 2 years ago
Table 1
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKkrMVdJRSlSK1YlWKs5IrATxksC87MyixDy4XGJeek5qIlwyJbEsMwXIS4ZJZiQilBYVZJZkINRCrEA1NBnFFKC+WAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [name = _t, #"type" = _t]), #"Added Custom" = Table.AddColumn(Source, "money I want to come", (k)=> Table.SelectRows(#"Table 2",each [name]=k[name]){0}[money]/List.Count(List.Select(Source[name],each _=k[name]))) in #"Added Custom"
You can do this in Power Query.
Group the the table with the types by name choosing all rows to get a nested table per name.
Merge by Name with the money query.
Expand the merge to get the money column
Add a column to get the row count of the nested tables.
Table.AddColumn(PREVIOUSSTEP, "nestedRowCount", each Table.RowCount([_nestedTable]), Int64.Type)
Replace the values in the money column with the money value divided by the nested row count.
Table.ReplaceValue(PREVIOUSSTEP,each [money],each [money]/[nestedRowCount],Replacer.ReplaceValue,{"money"})
Remove the nestedRowCount column
expand the nested table type column only.
You should get something like...