Consolidating 2 columns based on value in another column to another Worksheet

goby

New Member
Joined
Jul 27, 2023
Messages
5
Office Version
  1. 365
Platform
  1. Windows
I'm using the FILTER function to auto populate information from a primary Worksheet into specified columns of a secondary Worksheet. For reasons that I will leave unspecified, the primary Worksheet requires for each "Type" to have its own line item and be in different columns. Even if it is the same "Customer," "Sales Associate," or transaction in general.

I will pay my "Sales Associates" based on the amount of cake and ice cream they sell. I'd like to itemize their pay sheet but I want to consolidate "Ice Cream Type" and "Cake Type" to one column and maintain their individual rows.

I have attached some examples:
table1: Primary Worksheet (Job List)
table2: Secondary Worksheet (Sales Associate Pay Sheet)


Thanks!!
 

Attachments

  • table1.png
    table1.png
    49.2 KB · Views: 9
  • table2.png
    table2.png
    22.3 KB · Views: 9

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
power query
Book1
ABCDEFGHIJ
1CustomerSales personIce Cream TypeIce Cream QtyCake TypeCake QtySales personDessert TypeQuantity
2#1JimRed Velvet5JimRed Velvet5
3#2KevinMint20KevinMint20
4#3MaxMint23MaxMint23
5#4DonnaVanilla3DonnaVanilla3
6#4DonnaStrawberry15DonnaStrawberry18
7#5JamesStrawberry7JamesStrawberry7
8#6StevenPecan76StevenPecan83
9#6StevenRed Velvet12StevenRed Velvet12
10#7KevinRocky13KevinRocky13
11#8MaxRocky21MaxRocky21
12#9JimVanilla2JimVanilla2
13#10DonnaStrawberry3
14#11StevenPecan7
Sheet1


Now someonw else may be able to provide a tidier piece of code but here is mine
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer", type text}, {"Sales person", type text}, {"Ice Cream Type", type text}, {"Ice Cream Qty", Int64.Type}, {"Cake Type", type text}, {"Cake Qty", Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Customer"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"Sales person", "Ice Cream Qty", "Cake Qty"}, "Type", "Dessert Type"),
    #"Inserted Addition" = Table.AddColumn(#"Unpivoted Columns", "Quantity", each List.Sum({[Ice Cream Qty] , [Cake Qty]}), Int64.Type),
    #"Removed Columns1" = Table.RemoveColumns(#"Inserted Addition",{"Ice Cream Qty", "Cake Qty", "Type"}),
    #"Grouped Rows" = Table.Group(#"Removed Columns1", {"Sales person", "Dessert Type"}, {{"Quantity", each List.Sum([Quantity]), type number}})
in
    #"Grouped Rows"
 
Upvote 0
I suggest that you investigate XL2BB for providing sample data to make it easier for helpers by not having to manually type out sample data to test with.

Not exactly sure what you are after and cannot see where $152 or $51 in the results came from, but could this be any use?

goby.xlsm
ABCDEF
1CustomerSales personIce Cream TypeIce Cream QtyCake TypeCake Qty
2#1JimRed Velvet5
3#2KevinMint Chocolate Chip20
4#3MaxMint Chocolate Chip23
5#4DonnaVanilla3
6#4DonnaStrawberry15
7#5JamesStrawberry7
8#6StevenButter Pecan76
9#6StevenRed Velvet12
10#7KevinRocky Road13
11#8MaxRocky Road21
12#9JimVanilla2
13#10DonnaStrawberry3
14#11StevenButter Pecan7
Primary


goby.xlsm
ABCD
1Sales AssociateDessert TypeQuantity$$$
2JimRed Velvet5
3KevinMint Chocolate Chip20
4MaxMint Chocolate Chip23
5DonnaVanilla3
6DonnaStrawberry15
7JamesStrawberry7
8StevenButter Pecan76
9StevenRed Velvet12
10KevinRocky Road13
11MaxRocky Road21
12JimVanilla2
13DonnaStrawberry3
14StevenButter Pecan7
Secondary
Cell Formulas
RangeFormula
A2:C14A2=HSTACK(Table1[Sales person],Table1[Ice Cream Type]&Table1[Cake Type],Table1[Ice Cream Qty]+Table1[Cake Qty])
Dynamic array formulas.
 
Upvote 0
power query
Book1
ABCDEFGHIJ
1CustomerSales personIce Cream TypeIce Cream QtyCake TypeCake QtySales personDessert TypeQuantity
2#1JimRed Velvet5JimRed Velvet5
3#2KevinMint20KevinMint20
4#3MaxMint23MaxMint23
5#4DonnaVanilla3DonnaVanilla3
6#4DonnaStrawberry15DonnaStrawberry18
7#5JamesStrawberry7JamesStrawberry7
8#6StevenPecan76StevenPecan83
9#6StevenRed Velvet12StevenRed Velvet12
10#7KevinRocky13KevinRocky13
11#8MaxRocky21MaxRocky21
12#9JimVanilla2JimVanilla2
13#10DonnaStrawberry3
14#11StevenPecan7
Sheet1


Now someonw else may be able to provide a tidier piece of code but here is mine
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer", type text}, {"Sales person", type text}, {"Ice Cream Type", type text}, {"Ice Cream Qty", Int64.Type}, {"Cake Type", type text}, {"Cake Qty", Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Customer"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"Sales person", "Ice Cream Qty", "Cake Qty"}, "Type", "Dessert Type"),
    #"Inserted Addition" = Table.AddColumn(#"Unpivoted Columns", "Quantity", each List.Sum({[Ice Cream Qty] , [Cake Qty]}), Int64.Type),
    #"Removed Columns1" = Table.RemoveColumns(#"Inserted Addition",{"Ice Cream Qty", "Cake Qty", "Type"}),
    #"Grouped Rows" = Table.Group(#"Removed Columns1", {"Sales person", "Dessert Type"}, {{"Quantity", each List.Sum([Quantity]), type number}})
in
    #"Grouped Rows"
Thank you very much for taking the time and for the quick response @Kerryx. I should have clarified in my original post that I not looking for power query for this solution.
 
Upvote 0
I suggest that you investigate XL2BB for providing sample data to make it easier for helpers by not having to manually type out sample data to test with.

Not exactly sure what you are after and cannot see where $152 or $51 in the results came from, but could this be any use?

goby.xlsm
ABCDEF
1CustomerSales personIce Cream TypeIce Cream QtyCake TypeCake Qty
2#1JimRed Velvet5
3#2KevinMint Chocolate Chip20
4#3MaxMint Chocolate Chip23
5#4DonnaVanilla3
6#4DonnaStrawberry15
7#5JamesStrawberry7
8#6StevenButter Pecan76
9#6StevenRed Velvet12
10#7KevinRocky Road13
11#8MaxRocky Road21
12#9JimVanilla2
13#10DonnaStrawberry3
14#11StevenButter Pecan7
Primary


goby.xlsm
ABCD
1Sales AssociateDessert TypeQuantity$$$
2JimRed Velvet5
3KevinMint Chocolate Chip20
4MaxMint Chocolate Chip23
5DonnaVanilla3
6DonnaStrawberry15
7JamesStrawberry7
8StevenButter Pecan76
9StevenRed Velvet12
10KevinRocky Road13
11MaxRocky Road21
12JimVanilla2
13DonnaStrawberry3
14StevenButter Pecan7
Secondary
Cell Formulas
RangeFormula
A2:C14A2=HSTACK(Table1[Sales person],Table1[Ice Cream Type]&Table1[Cake Type],Table1[Ice Cream Qty]+Table1[Cake Qty])
Dynamic array formulas.
This is more what I am looking for. First, thank you for the suggestion, I will check that out for future reference.

I'd like to say: IF "Sales Person" is "Donna", THEN HSTACK. Is this possible?
 
Upvote 0
I'd like to say: IF "Sales Person" is "Donna", THEN HSTACK. Is this possible?

goby.xlsm
ABCDEF
1Sales AssociateDessert TypeQuantity$$$Sales Associate
2DonnaVanilla3Donna
3DonnaStrawberry15
4DonnaStrawberry3
5
Secondary
Cell Formulas
RangeFormula
A2:C4A2=LET(f,HSTACK(Table1[Sales person],Table1[Ice Cream Type]&Table1[Cake Type],Table1[Ice Cream Qty]+Table1[Cake Qty]),FILTER(f,TAKE(f,,1)=F2))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top