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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
AnonymeC
Regular Visitor

Equivalent to "Group By" function on multiple columns?

Hello,

 

I have a huge database that basically looks like:

 

CodeMarketFactoryJul 21Aug 21Sep 21....Apr 23May 23Jun 23
3424555332DACHXXX03424...225012

....

 

I have several rows with the same combination of Code/Market/Factory, and would like to consolidate all these rows in one unique row per combination. I know I can do it with "Group By" function, which is convenient with a small numbers of columns, but I have over 30 columns of date of shipments. Is there an easy way to do that without doing 30 times this with Group By?

AnonymeC_0-1687266738617.png

 

Thank you very much for your help.

 

1 ACCEPTED SOLUTION

Hi

UnPivot then pivot

let
Source = YourSource,
UnPivot = Table.UnpivotOtherColumns(Source, {"Code", "Market", "Factory"}, "Attribute", "Value"),
Pivot = Table.Pivot(UnPivot, List.Distinct(UnPivot[Attribute]), "Attribute", "Value", List.Sum)
in
Pivot

Stéphane 

View solution in original post

4 REPLIES 4
AnonymeC
Regular Visitor

Hello @AlienSx , yes that's right for the rows that have the same combination of Code/Market/Factory, I would like to do a sum.

 

Example:

If I have originally this table:

CodeMarketFactoryJul21Aug21Sep21...Apr23May23Jun23
0000011DACHPlant10238...0766
0000011DACHPlant1247...051

 

It should consolidate into:

CodeMarketFactoryJul21Aug21Sep21...Apr21May21Jun21
0000011DACHPlant122715...0817

 

Many thanks.

Hi

UnPivot then pivot

let
Source = YourSource,
UnPivot = Table.UnpivotOtherColumns(Source, {"Code", "Market", "Factory"}, "Attribute", "Value"),
Pivot = Table.Pivot(UnPivot, List.Distinct(UnPivot[Attribute]), "Attribute", "Value", List.Sum)
in
Pivot

Stéphane 

Thank you it worked perfectly.

AlienSx
Super User
Super User

Hello, @AnonymeC how would you like to summarize other columns? In general, one need to group by first 3 columns and select "All rows" as "operation". This gives you the whole table. One may apply a custom (user defined) function then to modify that table to get what you want. Just let us know what would you like to do to other columns - simple sum operation? 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors