Combine data from multiple sheets in new excel file - excel

I'm new to Excel so I'm sorry if this is newbie question.
I have one excel file with about 30 sheets containing sales for each day of the month for particular products. These sheets are named like "01.01.2022", "02.01.2022", "03.01.2022" and so on.
They are formatted like this
| productID | totalSold|
| --- | --- |
| 0 | 120 |
| 1 | 14 |
| 2 | 300 |
From these multiple sheets I need to add their totalSold values to an existing table that is formatted like this
productID
01.01.2022. expected
01.01.2022. sold
02.01.2022. expected
02.01.2022. sold
03.01.2022. expected
03.01.2022 sold
...
0
120
[dataFromOtherSheet]
110
dataFromOtherSheet
100
dataFromOtherSheet
1
14
[dataFromOtherSheet]
20
dataFromOtherSheet
10
dataFromOtherSheet
I already have data for "[date] expected" column.
Values in each row for "[date] sold" columns are sum of sales for that product in a given day.
I need to combine data from for example sheet called "01.01.2022" which containes all sales and place those values into column called "01.01.2022 sold". Their productID columns need to match and they are not in the same order in every sheet so I can't just use copy/paste, plus there are a lot of data so it's imposible. All tables in those sheets have same columns, only order of products is different that order in this existing table which contains expected and sold columns.

If I've understood right your problem you have to use summifs formula.
Assuming your items code are in A column and your item price are on B column you could write :
=summIfs('01.01.2022'!B:B;'01.01.2022'!A:A; A1)

Related

How to sort a column based on exact matches with another column

I have an inventory table that looks like this (subset):
part number | price | quantity
10115 | 14.95 | 10
1050 | 5.95 | 12
1074 | 7.49 | 8
110-1353 | 13.99 | 22
and i also have another table in sheet 2 that looks like this (subset):
part number | quantity
10023 | 1
110-1353 | 3
10115 | 2
20112 | 1
I want to basically subtract the quantities in the second table from the ones in the first table. What is the best way of doing this? I have looked in to VLOOKUP and INDEX MATCH but they are not quite right for this. Would this perhaps actually be better in say an Access DB ?
I have add another two columns next to sheet 1 last column. Let us assume that the second table range is A1:B5.
Image:
Formulas:
Column D:
=IFNA(VLOOKUP(A2,Sheet2!$A$2:$B$5,2,FALSE),0)
Column E:
=C2-D2
If you wanted to tackle this using MS Access, the SQL code might look like this:
select
t1.[part number],
t1.price,
t1.quantity - nz(t2.quantity, 0) as qty
from
inventory t1 left join table2 t2 on t1.[part number] = t2.[part number]
Here, I assume that you have a table called inventory and a table called table2 (change these to suit your database).
A left join is used to ensure that all records from inventory are returned, regardless of whether a match is found in table2, and the Nz function is used to return 0 for records for which there is no part number match in table2.

Excel Sumproduct/Sumif based on multiple criteria across two tables not in order

I've been struggling with an issue for a while now and haven't been able to find a solution, so any help would be greatly appreciated!
I'm trying to build a formula that sums up values from a column based on criteria spread across two tables (I've simplified below):
Table 1
+-------------+---------+---------------------+------------+----------+------+
| Customer ID | Twin ID | Customer Entry Date | Exit Date | Spending | Days |
+-------------+---------+---------------------+------------+----------+------+
| 111 | 333 | 24.12.2015 | 28.05.2018 | 5000 | 200 |
| 222 | 444 | 19.06.2014 | | 4000 | 300 |
+-------------+---------+---------------------+------------+----------+------+
Table 2
+-------------+---------+---------------------+-----------+----------+------+
| Customer ID | Twin ID | Customer Entry Date | Exit Date | Spending | Days |
+-------------+---------+---------------------+-----------+----------+------+
| 444 | | | | | 200 |
| 333 | | | | | 0 |
+-------------+---------+---------------------+-----------+----------+------+
I now need to find a formula, that will allow me to sum up the column "Spending" from table 1 based on the following criteria:
"Twin ID" in Table 1 is not empty and the value matches the value "Customer ID" in Table 2 --> this has been the main complication for me, as the Customer IDs in Table 2 are in a different order than the Twin IDs in Table 1
"Entry Date" in Table 1 is < a specific date
"Exit Date" in Table 1 is >= a specific date or empty
"Days" in Table 2 is >0 (for the respective Customer ID that matches the Twin ID from Table 1)
Or in other words: "If customers 111,222 etc. have a twin, and this twin has days >0, and the entry and exit dates of the customer are < > a specific date or empty, then sum up the spending of those customers"
I've tried various iterations of the SUMPRODUCT formula, and this one currently works as long as the two tables are in the same order (i. e. Twin ID "333" is in row 2 in Table 1 and in row 2 in Table 2):
=SUMPRODUCT(--(Table1!Customer Entry Date<DATE1);--(Table1!Exit Date>=Date2);--(Table1!TwinID<>"");--(Table2!Days>0);Table1!Spending)
Is there any way to make this formula work regardless of the order of the row items (i. e. Twin ID "333" is in row 2 in Table 1 and in row 3 in Table 2)?
Any help would be greatly appreciated!
Try this
=SUMPRODUCT((Table1!Customer_Entry_Date<Date1)*(Table1!Customer_Entry_Date>Date2)*(Table1!Twin_ID<>"")*(COUNTIFS(Table2!Customer_ID,Table1!Twin_ID,Table2!Days,">0")>0)*Table1!Spending)
It's similar to your formula, but uses Countifs to see if a matching Customer ID for Table 1's Twin ID is anywhere in table 2.
Note that your named ranges (if that's what you're using) should not include the column headers or else you'll get a #Value error when it tries to do the multiplication.
You could avoid it by putting IF(Isnumber()) around the last part of the bracket, but then it would have to be entered as an array formula
=SUM((Table1!Customer_Entry_Date<Date1)*(Table1!Customer_Entry_Date>Date2)*(Table1!Twin_ID<>"")*(COUNTIFS(Table2!Customer_ID,Table1!Twin_ID,Table2!Days,">0")>0)*IF(ISNUMBER(Table1!Spending),Table1!Spending))
I managed to solve the issue.
Anyone facing a similar problem, please see the example file for solution: https://wetransfer.com/downloads/90aedc5943f52274e36102a79e23c18e20180628212338/2fd1c1
=+SUMPRODUCT(SUMIF(Table1TwinID;Table2CustomerID;Table1Spending)*(Table2Days>0)*((COUNTIFS(Table1TwinID;Table2CustomerID;Table1EntryDate;"<"&DATE1)*COUNTIFS(Table1TwinID;Table2CustomerID;Table1ExitDate;">="&DATE2))+(COUNTIFS(Table1TwinID;Table2CustomerID;Table1EntryDate;"<"&DATE1)*COUNTIFS(Table1TwinID;Table2CustomerID;Table1ExitDate;""))))

Percentage of Sum of two Pivot cells

I'm trying to work out a small problem with my excel Pivot table. I have data from a Excel Sheet which i have made a Pivot table of. The data is structured as below
Name | Count Cell1 | Sum of Cell 2 |
Eric | 25 | 5 |
Sam | 5 | 1 |
Joe | 10 | 5 |
What i want to have is a formula that takes the Count of Cell 1 and divide it by Sum of Cell 2 and display it in % like the example below.
Name | Count Cell1 | Sum of Cell 2 | Difference|
------------------------------------------------
Eric | 25 | 5 | 20% |
Sam | 5 | 1 | 20% |
Joe | 10 | 5 | 50% |
All formulas i have tried only uses the original Table cells and not the sums of them.
So is there a smart way to have a formula lookup inside of a pivot table and display it in %?
In your Pivot Table, you can enter a calculated field to do what you want.
Select somewhere in your pivot table (e.g. one of the Sum of Cell2 fields)
In the PivotTable Tools > Options ribbon, in the Calculations section, click Fields, Items & Sets and from there pick Calculated Field
Change the name to Difference and the Formula =Cell2/Cell1
In the Field Settings for that field, change the Custom Name to Difference and Number Format to Percentage
EDIT - question updated for Count & Sum
So, as far as I can see, trying to do the combination of Sum/Count really upsets it... the only workaround I could find was adding a helper column in the data source with just the number 1... in that way, the sum of that gives you the count, and so the Calculated Field can be Cell2/HelperColumn -horrible!

Counting the number of older siblings in an Excel spreadsheet

I have a longitudinal spreadsheet of adolescent growth.
ID | CollectionDate | DOB | MOTHER ID | Sex
1 | 1Aug03 | 3Apr90 | 12 | 1
1 | 4Sept04 | 3Apr90 | 12 | 1
1 | 1Sept05 | 3Apr90 | 12 | 1
2 | 1Aug03 | 21Dec91 | 12 | 0
2 | 4Sept04 | 21Dec91 | 12 | 0
2 | 1Sept05 | 21Dec91 | 12 | 0
3 | 1Aug03 | 30Jan89 | 23 | 0
3 | 4Sept04 | 30Jan89 | 23 | 0
This is a sample of how my data is formatted and some of the variables that I have. As you can see, since it is longitudinal, each individual has multiple measurements. In the actual database there are over 10 measurements per individual and over 250 individuals.
What I am wanting to do is input a value signifying the number of older brothers and older sisters each individual has. That is why I have included the Mother ID (because it represents genetic relatedness) and sex. These new variable columns would just say how many older siblings of each sex each individual has. Is there a formula that I could use to do this quickly?
=COUNTIFS($B:$B,"<>"&$B2,$H:$H,$H2,$AI:$AI,$AI2,$J:$J,"<"&$J2)
Create a column named Distinct with this formula
=1/COUNTIF([ID],[#ID])
Then you can find all the older 0-sexed siblings like this
=SUMPRODUCT(([DOB]>[#DOB])*([MOTHERID]=[#MOTHERID])*([Sex]=0)*([Distinct]))
Note that I made the data a Table and used table notation. If you're not familiar [COLUMNNAME] refers to the whole column and [#COLUMNNAME] refers to the value in that column on the current row. It's similar to saying $A:$A and A2 if you're dealing with column A.
The first formula gives you a value to count that will always result in 1 for a particular ID. So ID=1 has three lines and Distinct will result in .33333 for each line. When you add up the three lines you get 1. This is similar to a SELECT DISTINCT in Sql parlance.
The SUMPRODUCT formula sums [Distinct] for every row where the DOB is greater than the current DOB, the Mother is the same as the current Mother, and the Sex is zero.
I have a possible solution. It involves adding two columns -- One for "# older siblings" and one for "unique?". So here are all the headings I have currently:
A -- ID
B -- CollectionDate
C -- DOB
D -- MOTHER ID
E -- Sex
F -- # older siblings
G -- unique?
In G2, I added the following formula:
=IF(A2=A1,0,1)
And dragged down. As long as the data is sorted by ID, this will only display "1" once for each unique person.
In F2, I added the following formula:
=COUNTIFS(G:G,"=1",D:D,"="&D2,C:C,"<"&C2)
And dragged down. It seemed to work correctly for the sample data you provided.
The stipulations are:
You would need the two columns.
The data would need to be sorted by ID
I hope this helps.
You need a formula like this (for example, for row 2):
=COUNTIFS($A:$A,"<>"&$A2,$E:$E,$E2,$D:$D,$D2,$C:$C,"<"&$C2)
Assuming E:E is column for sex, D:D is column for mother ID and C:C is column for DOB.
Write this formula in H2 cell for example and drag it down.

Excel Formulas: Show total based on date entry

I've got a spreadsheet with two columns that represent the number of processed records, and the date the records were processed. In some cases, the records can be processed in multiple batches, so the document looks something like this:
33 4/1/2009
22 4/1/2009
12 4/2/2009
13 4/4/2009
36 4/4/2009
I'm trying to add a new set of columns that contain a date, and shows the total number of records for that date, automagically:
4/1/2009 55
4/2/2009 12
4/3/2009 0
4/4/2009 49
I know how to do this algorithmically, and I could probably manipulate the spreadsheet outside of Excel, but I'm trying to do this in the live spreadsheet, and am a bit bewildered as to how to pull it off.
Any ideas?
Thanks!
IVR Avenger
Will the SUMIF function work for you? SUMIF([range],[criteria],[sum_range]) I think you could set range = the set of cells containing dates in your first listing, criteria would be the cell containing the date in the second listing, and sum_range would be the counts in the first column of your first listing.
I would suggest using a Pivot Table. Put the dates into the row area and 'sum of' records in the data area. Nothing in the columns area.
A pivot table will be more dynamic than a formula solution because it will only show you dates that exist.
Assuming your dates are in column B and the numbers to be accumulated are in A, you could try something like this:
| A | B | C D
1 | 33 | 4/1/2009 | =MIN(B:B) | {=SUM(IF(B1:B5=C1,A1:A5,0))} |
2 | 22 | 4/1/2009 | =C1+1 | {=SUM(IF(B1:B5=C2,A1:A5,0))} |
3 | 12 | 4/2/2009 | =C2+1 | {=SUM(IF(B1:B5=C3,A1:A5,0))} |
4 | 13 | 4/4/2009 | =C3+1 | {=SUM(IF(B1:B5=C4,A1:A5,0))} |
5 | 36 | 4/4/2009 | =C4+1 | {=SUM(IF(B1:B5=C5,A1:A5,0))} |
Note the {} which signifies an array formula (input using Control-Shift-Enter) for any non-trivial amount of data it's heaps faster than SUMIF().
I'd be inclined to define dynamic names for the A1:A5 and B1:B5 parts, something like
=OFFSET(A1,0,0,COUNT(A:A),1)
so that I didn't have to keep fixing up my formulae.
There's still a manual element: adding new rows for extra dates, for example - that might be a good place for a little VBA. Alternatively, if you can get away with showing, for example, the last 90 days' totals, then you could fix the number of rows used.

Resources