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
krishma
Regular Visitor

Power BI Desktop query

There are two tables which are mapped on the basis of name:
table 1                           

 

nametype
rama
shaymb
kirana
angleab
davidc
anghaa
arpithab
ramb
kiranc
davida

 

Table 2

namemoney
ram200
shaym300
kiran500
anglea600
david700
angha800
arpitha100

 

When i am doing left join on the bass of name, it gives me

nametypemoney
rama200
shaymb300
kirana500
angleab600
davidc700
anghaa800
arpithab200
ramb200
kiranc500
davida700

 

but i want output like this: total money for that name should be divided equally for each type for ex: Ram has two types a and b and money is 200 so in the final table it should be like
Ram a 100
ram b 100

 

below output is what i am looking for

nametypemoney I want to come
anghaa800
angleab600
arpithab200
davidc350
davida350
kirana250
kiranc250
rama100
ramb100
shaymb300

 

can someplease please help me

2 ACCEPTED SOLUTIONS
jgeddes
Super User
Super User

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...

jgeddes_0-1717685410547.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

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"

 

 

View solution in original post

5 REPLIES 5
miTutorials
Super User
Super User

Check the attached pbix where I have achieved this using measures.

 

jgeddes
Super User
Super User

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...

jgeddes_0-1717685410547.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Thank you so much it helped me alot.
@lbendlin  @jgeddes 

krishma
Regular Visitor

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"

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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