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
OscarSuarez10
Helper III
Helper III

Filter by letter and sum by year

Hello, I´m trying to sum the production of some products by year but I can´t sum all the products, I only want to sum some specific names, for example in the following table I only want the production of the products that have the word cheme in their name, as you can see the sum for the first year is 153 and for the sencond year is 1099, How can I do this using power query?

 

Yearproductproduction  
1arbol110cheme year1153
1arbol220  
1arbol35  
1arbol44  
1cheme178  
1cheme252  
1cheme313  
1cheme410  
1arbol59  
1arbol64  
1arbol71  
2arbol178  
2arbol245  
2arbol398  
2arbol412  
2cheme1987cheme year21099
2cheme212  
2cheme345  
2cheme455  
2arbol53  
2arbol611  
2arbol722  
1 ACCEPTED SOLUTION
Nolock
Resident Rockstar
Resident Rockstar

Hi @OscarSuarez10,

I've prepared a solution for you. All that you can just click together in the PowerQuery Editor UI. Go through all the steps and if you don't understand one of them, don't hesitate to ask.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY/BCsMgEET/xXMOdXWjfkvIoS1CDgmF/v+hO1LEkdyGh+7M2zbn3eKe39fnRPAPty8DEwsysWBBGUULsaP3Ua+KkDIzXFNhhms+MIs3S9RCYbRSa0MJPxuSUes/REatqMwwpEzv2hDprIuVnBjKzcPAJd1Mp2KYBUYw85MH1MQq9h8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ear = _t, product = _t, production = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ear", Int64.Type}, {"product", type text}, {"production", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each Text.Contains([product], "cheme")),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"ear"}, {{"Cheme Production", each List.Sum([production]), type number}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Cheme Year", each "cheme year" & Text.From([ear])),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"ear"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Cheme Year", "Cheme Production"})
in
    #"Reordered Columns"

Capture.PNG

View solution in original post

1 REPLY 1
Nolock
Resident Rockstar
Resident Rockstar

Hi @OscarSuarez10,

I've prepared a solution for you. All that you can just click together in the PowerQuery Editor UI. Go through all the steps and if you don't understand one of them, don't hesitate to ask.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY/BCsMgEET/xXMOdXWjfkvIoS1CDgmF/v+hO1LEkdyGh+7M2zbn3eKe39fnRPAPty8DEwsysWBBGUULsaP3Ua+KkDIzXFNhhms+MIs3S9RCYbRSa0MJPxuSUes/REatqMwwpEzv2hDprIuVnBjKzcPAJd1Mp2KYBUYw85MH1MQq9h8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ear = _t, product = _t, production = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ear", Int64.Type}, {"product", type text}, {"production", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each Text.Contains([product], "cheme")),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"ear"}, {{"Cheme Production", each List.Sum([production]), type number}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Cheme Year", each "cheme year" & Text.From([ear])),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"ear"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Cheme Year", "Cheme Production"})
in
    #"Reordered Columns"

Capture.PNG

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.

Top Solution Authors
Top Kudoed Authors