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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

Summing values by category in "transform data" to create query capable of one to many relationship

Hi, 

 

I have a query with multiple AFE numbers. Within each afe number are a couple of major codes and minor codes. My end goal is to sum the costs associated with each AFE's major and minor cost so that I can have 1 row per AFE, major and minor code. Once the query is in this format, I will be able to create a one to many relationship with another query to transfer these values using the related function. I believe this has to be done in the "transform data" query editor otherwise I'll end up with a many to many relationship correct? 

 

The first table is an example of what my data looks like. The second table is the end result I'm shooting for. 

 

Thank you in advance!

 

AFEMajorMinorCost
10130010
10130020
10140010
1014005
20130020
20130010
20140020
20240010
20240020

 

AFEMajorMinorCost
10130030
10140015
20130030
20140020
20240030

 

 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Just use the Group By feature of the Query Editor.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRQ0lEyBGJjAzDLQClWB0PUCE3UBKtaiKgpWNAIqwFGWC0zQjUAWa0RumVooiC1sQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [AFE = _t, Major = _t, Minor = _t, Cost = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"AFE", Int64.Type}, {"Major", Int64.Type}, {"Minor", Int64.Type}, {"Cost", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"AFE", "Major", "Minor"}, {{"Cost", each List.Sum([Cost]), type number}})
in
    #"Grouped Rows"


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

1 REPLY 1
Greg_Deckler
Super User
Super User

Just use the Group By feature of the Query Editor.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRQ0lEyBGJjAzDLQClWB0PUCE3UBKtaiKgpWNAIqwFGWC0zQjUAWa0RumVooiC1sQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [AFE = _t, Major = _t, Minor = _t, Cost = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"AFE", Int64.Type}, {"Major", Int64.Type}, {"Minor", Int64.Type}, {"Cost", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"AFE", "Major", "Minor"}, {{"Cost", each List.Sum([Cost]), type number}})
in
    #"Grouped Rows"


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Top Solution Authors