יום שישי, 9 בפברואר 2024

Combine data from multiple sheets without PQ

 

Combine data from multiple sheets without PQ

We all know that Power Query is the ideal tool to combine data from multiple tables/sheets/files etc.
But sometimes one can use a simpler, faster solution. This solution will still work even if the data changes.

Consider the following scenario:
I and some friends are planning on a four-day camp in the desert. We have prepared the list of products and quantities per product for each day. In order to buy these products, we need to find out the total quantity for each product that we are going to consume in our trip. Of course, some items might repeat themselves in several days. And of course, as stated above, we want the solution to be dynamic: if you add/delete a product, or if you modify a product’s quantity, we want this to be reflected in the purchase list.

So here’s the data, in 4 sheets: Day1 to Day4

                        Day 1: Products and Quantity



                        Day 2: Products and Quantity

 

 

                        Day 3: Products and Quantity

 

                        Day 4: Products and Quantity

 

We have two solutions, using VSTACK

Solution 1:
1)
Create a dynamic array of all the data in all four sheets.
2) Use this array in a pivot table. All the “empty” rows of array are grouped into one row in the pivot table.



    The Pivot Table uses the array created by VSTACK

 

3) This “0” row of the Pivot Table can easily be eliminated by filtering it out.



        The Pivot Table after filtering out the “0” row

 

 

Solution 2:

Using both VSTACK and the new GROUPBY functions, we can achieve the same in one formula.
The same method may be employed to get rid of the “0” row (or even the “total” row if you omitted the 4th argument to the GROUPBY function).



        VSTACK & GROUPBY instead of Power Query

 




 

 


אין תגובות:

הוסף רשומת תגובה