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

@ 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!:
The Definitive Guide to Power Query (M)

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"

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.