Sum of specific number of rows for a id in excel - excel

I am pretty new to excel formulas. I want to calculate the sum of prices for every unique id. Using SUMIF I was able to do that for every unique id but I only want to calculate the sum of a number of rows for that id.
=SumIF(A:A;C2;B:B)
Sample data is attached. Actual data set is quite large. For Example, For Id 1, I only want to calculate the sum of first 3 rows (Column price) corressponding to that id, for id 2 the sum of first 4 rows and so on.
Sample data:

This formula works for sorted and non sorted data:
=SUMIF($A$2:INDEX(A:A,AGGREGATE(15,6,ROW($A$2:$A$20)/($A$2:$A$20=C2),D2)),C2,$B$2:INDEX(B:B,AGGREGATE(15,6,ROW($A$2:$A$20)/($A$2:$A$20=C2),D2)))

Enter this as an array formula (ctrl+shift+enter):
=IFERROR(SUMPRODUCT(IF(ROW($A$2:$A$20)>SMALL(IF($A$2:$A$20=C2,ROW($A$2:$A$20),FALSE),MIN(D2,COUNTIF($A$2:$A$20,C2))),0,1),IF($A$2:$A$20=C2,1,0),$B$2:$B$20),0)

Related

Counting all units aligned to an order number and returning the value

I have a list of 25,000 orders. I want to find the total number of units in each order, and return that. Right now column A is the order number, and column B is the number of units broken down by line item as they were aligned to SKUs. So you will see order numbers repeat in column A based on how many SKUs were in that order. If there were 3 different SKUs ordered, such as in order 5, there will be three rows for order 5.
I want to write a function that checks column D for the order number, then searches column a for all the times that number is there and then sums the numbers aligned to that order in column B.
For example, cell D4 has order 3, and then searches column A for "3" and then finds and sums all the numbers in column B that are aligned to a "3" in column A. In this case that would return 47 as the answer.
I have been able to write a simple function to find that, but I wasn't able to increment it across all 25k orders.
ORDER_DATA
in cell E2:
=SUMIF(A:A,D2,B:B)
Try the following array formula-
=ArrayFormula(IF(D2:D="",,SUMIF(A2:A,D2:D,B2:B)))

How to skip counting same value set in 2 columns that appears in another 2 columns set

Good day, I need some help on how to form an Excel formula to count distinct for values in 2 columns with other columns:
I want to count a number of subjects assigned to "ummu", but that same subject name appears again shouldn't be count. In this example, the count will return 4. How can I achieve this using excel formula?

Using Correl Function in Excel for Varying Array Sizes

So the current setup of the problem at hand is that I have 4 columns, Employee ID, Category 1, Category 2, and Category 3. I need to find the correlation between Category 1 & Category 2, Category 1 & Category 3, and Category 2 & Category 3 for each Employee ID. The issue is that the array length for each Employee ID is different. Some employees will have 5 records, some employees will have 8 records to their ID.
This problem would be simple if the Subtotal button had the CORREL function built into it given its grouping by feature.
How would I go about calculating the 3 correlation coefficients for each unique Employee ID? Excel function or VBA works
You need to use an array formula. Please see this screen shot of a sample situation:
As you can see the formula for cell G2 is: =CORREL(IF($A$2:$A$16=F2,$B$2:$B$16,""), IF($A$2:$A$16=F2,$C$2:$C$16,"")) That is saying if cell in column A matches your employeeId, include the cell in corresponding column in the array (Column B for the first IF and Column C for the second ID). After entering in the formula you need to make sure you hit Ctrl+Shift+Enter to tell excel you want to do an array formula or Command+Enter on a Mac.
You obviously need to modify the formula to fit the size of your data and you can copy that formula to any cells if you setup your $s correctly.

Need help in excel formula

1) I have two tables. 1st table contains data for more then 20,000 rows and 2nd table I already have the following columns details i.e. Region, Item, Number and I just have to get the Total value of the product from the 1st table
2) There are two types of prices in the 1st table . One is Retail Price and Another one is a Wholesale price
3) In each of the regions Rep, Item and Numbers are same in most of the cases, but the Total price is different
4) I am able to get the Total price details in 2nd table through vlookup formula (After concatinating the following columns i.e. Region, Item and Number from both the tables) wherever there is an account number for retail price
5) Currently I am manually updating "Total Price" details in 2nd table for Wholesale price which is taking lot of time.
Is it possible to build a formula to get the wholesale price details in the 2nd table, since there are more then one account number, but the price is same
If the wholesale price is the lowest price for the specific item, then you can find it with the formulas MIN and IF.
Based on your screen shot:
D is the column with the list of items
I5 is the cell with the item name for which you want to find the wholesale price
F is the column with the list of prices
If you enter the following formula in cell K5, it should find the lowest price for pencils
=MIN(IF(D:D=I5,F:F))
On this link, there is an explanation if you want to use multiple criteria.
http://www.contextures.com/excelminmaxfunction.html
try the sumifs function.
It takes multiple arguments and criteria. So it should look something like:
cell value at j5 = sumifs(f3:f23, b3:b23, h5, d3:d23, i5....)
you need to mark off which rows in your first table are wholesale selling. So it should be a column of some kind. Once you do that, let's say in column G, then you add onto the sumifs function...
, g3:g23, L5)
What you're doing is summing up all of the values in column F where h5 (region) matches in b3:b23, i5 (item) match in d3:d23, and where L5 (retail type) match in a new column g2:g23.
This will find all of the values that match that criteria exactly.
Vlookup is useful, but it's harder to scale IMO than the advanced if functions.
SUMIFS is probably the better way to go on this one, but as an alternative there is also SUMPRODUCT.
=SUMPRODUCT(($H3=$B$3:$B$20004)*($I3=$D$3:$D$20004)*($J3=$E$3:$E$20004)*($F$3:$F$20004))
The * acts as an AND statement in a logical check, and each of the ($H3=$B$3:$B$20004) is a logical check. When the row is true it will evaluate to 1. When it is false it will evaluate to 0. in the end you wind up with a list of prices or 0s that get summed. The end result is the sum of everything that matches your criteria.
The danger of using this formula is that it can get labour intensive as it is performing array calculations without being an array formula.

How do I check for duplicate rows and do calculate on that rows in excel file?

I have one excel file which is having data like following
CUSIP Quantity Date Price
AF0 500000 5/6/2013 1
AE4 400000 5/6/2013 1.0825
AE4 500 5/6/2013 1
I need to check for column CUSIP and Date
If I'm having duplicate CUSIP for same date then I need to do following calculation.
1.Need to add Quantity for both of them instead of showing duplicate records need to show only one record( sum of Quantity).
2.Need to do calculation on Price as well like following
NewPrice = ((400000 * 1.0825) + (500 * 1.00))/(400000 + 500) = 1.08148
For example in using above data
Need to show output like
CUSIP Quantity Date Price
AF0 500000 5/6/2013 1
AE4 400500 5/6/2013 1.082397004
How do I achieve this in excel file using LOOKUP or else ?
Okay, after quite some research (interesting question by the way!), I came up with this:
=IF(COUNTIF($A$2:A2,A2)>1,"",SUMIF(A:A,A2,B:B))
=IF(COUNTIF($A$2:A2,A2)>1,"",SUMPRODUCT(--(A:A=A2),B:B,D:D)/SUMIF(A:A,A2,B:B))
Put these in cell D2 and E2 respectively (which is the next column after Price and in the row of CUSIP AF0).
And fill to the bottom of the worksheet to get the weighted average price or each CUSIP.
The first formula gives you the total quantity for the CUSIP and the second gives you the average price.
Copy and paste values for those two columns after calculation.
Put a filter and remove all the rows where the total quantity and average price is blank, and sort to make the worksheet neat.
Let me know if this works for you! I tried it on your sample data and it seems to be working. It's my first time using SUMPRODUCT ^^;
SUMPRODUCT(--(A:A=A2)
This bit returns the rows from column A where it equals to the row's CUSIP.
SUMPRODUCT(--(A:A=A2),B:B,D:D
This additional bit tells excel to multiply the values in column B and D of each returned row found above and SUMPRODUCT adds each result together.
EDIT:
I actually forgot about the date. You could maybe add a helper column where you'll generate an identifier to separate the different dates. To make it, you'll have to make a concatenate.
Hence in cell F2, you put:
=CONCATENATE(A2,C2)
In the formulae for cells D2 and E2, you will have to change them so they become:
=IF(COUNTIF($F$2:F2,F2)>1,"",SUMIF(A:A,A2,B:B))
=IF(COUNTIF($F$2:F2,F2)>1,"",SUMPRODUCT(--(A:A=A2),B:B,D:D)/SUMIF(A:A,A2,B:B))
reEDIT: Oops, put the wrong reference. Fixed now.

Resources