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

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
ellysoo
Regular Visitor

Multiple type summing up by location

Hi, I would need enlightenment from the experts here on how can I do the following with power query.

 

For below data, how can I generate the total of each fruits by Operating Office and drill down by Location?

 

Operating OfficeLocationFruit 1Fruit 1 QuantityFruit 2Fruit 2 Quantity
HQEast MarketPear4Orange6
Office 1West MarketLemon10Peach3
HQNorth MarketOrange20Apple 14
HQCentral MarketApple12Mango10
Office 2South MarketPeach4Banana6
1 ACCEPTED SOLUTION
wdx223_Daniel
Community Champion
Community Champion

suggest to transform data like this

wdx223_Daniel_0-1679886703840.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8ghU0lFyTSwuUfBNLMpOLQHyAlITi4CUCRD7FyXmpacCGWZKsTrRSv5paZnJqQqGQIHwVGQtPqm5+XlA2tAAoj85A0gbg/WALfDLLyrJQCiHG2sEUu9YUJCTqgDSbYLQ4ZyaV1KUmIPQA1YFUmQEJHyB+vMh9iG5CyQTnF+KbBPMLSDPOCXmASHEM7EA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Operating Office" = _t, Location = _t, #"Fruit 1" = _t, #"Fruit 1 Quantity" = _t, #"Fruit 2" = _t, #"Fruit 2 Quantity" = _t]),
    Custom1 = #table(List.FirstN(Table.ColumnNames(Source),2)&{"Fruit","Quantity"},List.TransformMany(Table.ToRows(Source),each List.Split(List.Skip(_,2),2),(x,y)=>List.FirstN(x,2)&y)),
    #"Changed Type" = Table.TransformColumnTypes(Custom1,{{"Operating Office", type text}, {"Location", type text}, {"Fruit", type text}, {"Quantity", Int64.Type}})
in
    #"Changed Type"

 

View solution in original post

1 REPLY 1
wdx223_Daniel
Community Champion
Community Champion

suggest to transform data like this

wdx223_Daniel_0-1679886703840.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8ghU0lFyTSwuUfBNLMpOLQHyAlITi4CUCRD7FyXmpacCGWZKsTrRSv5paZnJqQqGQIHwVGQtPqm5+XlA2tAAoj85A0gbg/WALfDLLyrJQCiHG2sEUu9YUJCTqgDSbYLQ4ZyaV1KUmIPQA1YFUmQEJHyB+vMh9iG5CyQTnF+KbBPMLSDPOCXmASHEM7EA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Operating Office" = _t, Location = _t, #"Fruit 1" = _t, #"Fruit 1 Quantity" = _t, #"Fruit 2" = _t, #"Fruit 2 Quantity" = _t]),
    Custom1 = #table(List.FirstN(Table.ColumnNames(Source),2)&{"Fruit","Quantity"},List.TransformMany(Table.ToRows(Source),each List.Split(List.Skip(_,2),2),(x,y)=>List.FirstN(x,2)&y)),
    #"Changed Type" = Table.TransformColumnTypes(Custom1,{{"Operating Office", type text}, {"Location", type text}, {"Fruit", type text}, {"Quantity", Int64.Type}})
in
    #"Changed Type"

 

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.