I have a list of cargo items, each with a Quantity, Length, Width, Height and Weight. I'm trying to produce a summary of how their dimensions are distributed (ideally taking the quantities of each into account, but that's a step beyond where I'm stuck).
I have one spreadsheet with length values in 0.1m intervals in Statistics!A2:A302, and I'm hoping to put the quantity for each length interval in Statistics!B2:B302. The quantities per item are in 'Steel plate list'!$B$3:$B$1002, and the lengths to look at are in 'Steel plate list'!$C$3:$C$1002.
Now, at the moment I have the following formula in Statistics!B2 and filled down:
=COUNTIFS('Steel plate list'!$C$3:$C$1002, ">="&A2, 'Steel plate list'!$C$3:$C$1002, "<"&A3)
That works fine, gives me the number of line items that have that length, but it means that, for instance, a single 8-metre plate counts as heavily as 260 12-metre plates. Is there any way to take the quantities into account? I've thought of using a VLOOKUP for it, but I can't think of a way to make that work.
Any thoughts?
Instead of COUNTIFS, you should be using SUMIFS. SUMIFS works like COUNTIFS, except that it adds all rows which match your criteria, instead of simply counting them.
So your formula would look almost identical to what you currently have [the first argument passed to SUMIFS is the range which you want summed, and the following arguments alternate as being either the range to look for a criteria, or the criteria to use agaisnt that range]:
=SUMIFS('Steel plate list'!$B$3:$B$1002,'Steel plate list'!$C$3:$C$1002, ">="&A2, 'Steel plate list'!$C$3:$C$1002, "<"&A3)
As you can see, apart from changing the function from COUNTIFS to SUMIFS, all I needed to do was add the first argument referencing column B on the other sheet, which holds the quantities for each row matching all criteria.
To sum the quantity (not sum the dimensions) of the pieces you can use this array formula:
=SUM(IF('Steel plate list'!$B$2:$B$10>=A2,IF('Steel plate list'!$B$2:$B$10<A3,'Steel plate list'!$A$2:$A$10,0),0))
Press Ctrl+Shift+Enter to create the array formula.
This assumes that column A contains Quantity and column B contains Length.
The formula will show that you have how many pieces for a given dimension on the Statistic page. Example, 1 piece of 8-meter and 260 12-meter pieces.
Related
The first table below shows how much each person owes and who pays it (it's part of a larger model so I simplified it for our purposes here).
Our goal in the second table below is to give a sum when both the column and row value match.
For example: A (column C) paid $244.17 (D36:H48) in expenses for B (row 35).
Where am I wrong here? I have tried different methods suggested here.
This is another alternative, that only requires to extend the formula down, but not to the left, because on each row it returns an array with all column values. In cell I3 enter the following formula:
=MMULT(N(TRANSPOSE($A$3:$A$15=H3)),IF($B$3:$F$15="", 0, $B$3:$F$15))
or using LET to avoid repetition of the same range:
=LET(set, $B$3:$F$15, MMULT(N(TRANSPOSE($A$3:$A$15=H3)),IF(set="", 0, set))
Notes:
MMULT only works with numeric values, so empty cells need to be converted.
You can replace TRANSPOSE with TOROW if you want.
$-notation is not required in H3, because we extend the formula only down
Here is the output:
Note: This solution assumes header values to compare are the same, i.e. same values for Paid For (I2:M2) and Paid By (H3:H7). Which is the most common situation. That is why in the formula only Paid By column is used. If that is not the case, then the solution provided by #JB-007 is more flexible, because the values can be different, but then you need to extend the formula in both directions.
screenshot/s here refer:
=SUM($C$4:$E$6*($C$3:$E$3=C$8)*($B$4:$B$6=$B9))
(sumifs will really struglly to work across different dimensions)
PS - as you'll see most will advise sumproduct - I think it's overdue deprecation because there's very little (if anything) you can do with sumproduct that you cannot with sum. You can even do counts with sum SUM(1*($C$3:$E$3=C$8)*($B$4:$B$6=$B9))) returns the count of where these values are equivalent...
Save yourself the extra seven letters over and over! ☺
I have array of numbers in a single column like this:
I want only that numbers for which corresponding negative numbers exist. If number exist 2 times, but negative number exist only one time, then I wanted to retain one positive and one negative number. Similarly, if number exists 3 times, and negative number appears only two times, then I want 2 set of numbers including positive and negative. In this case, I wanted to get output:
5 2 -2 -5
Orders of numbers are not relevant for me. Please do not use VBA. You can create multiple column and apply filter at the end.
Thank you for the response, but I wanted to get the data in column next to the values. Like:
5
2
-2
-5
Please help.
Here's another Office 365 solution:
Name the data range DATA
Put this formula anywhere: =CONCAT(REPT(-ROW(A1:A100)&" "&ROW(A1:A100)&" ",COUNTIF(DATA,"="&ROW(A1:A100)*IF(COUNTIF(DATA,"="&-ROW(A1:A100))<COUNTIF(DATA,"="&ROW(A1:A100)),-1,1))))
That will output the pairs into one cell.
Here's a slightly modified Step 2, which excludes duplicates: =CONCAT(IF((COUNTIF(DATA,"="&-ROW(A1:A100))>0)*(COUNTIF(DATA,"="&ROW(A1:A100))>0),-ROW(A1:A100)&" "&ROW(A1:A100)&" ",""))
Looks like this:
The data doesn't need to be sorted. Both methods work up to 100, but you can easily expand that by changing A100 to A1000 or whatever you need.
Use the vlookup formula to identify the rows, and you can use the Filter & Unique formula to get the list, or a pivot table.
First, immediately next to your data use the formula:
=vlookup(A1*-1,$A$1:$A$1,1,0)
For non-365:
This will produce an error for each instance that doesn't have a match. You can filter at this point to get your list from the existing table. You can also create a pivot table under the Data tab of your ribbon and inserting a pivot table. Filter the #N/A from there to get an exclusive list without hidden rows.
For 365:
You can use the following combination of formulas to get the exclusive list as well.
=UNIQUE(FILTER(B1:B8,ISNUMBER(B1:B8)),0,0) or =UNIQUE(FILTER($B$1:$B$8,ISNUMBER($B$1:$B$8)),0,0) should yield the same results
As ScottCraner mentioned, you can circumvent the helper column in 365 by modifying the formula a bit more:
=UNIQUE(FILTER(A1:A8,ISNUMBER(MATCH(-A1:A8,A1:A8,0)),"")
The Match here is doing something similar to the Vlookup, but housing that logic within the formula, so it's a cleaner solution in my opinion.
Using your data the result was { -5,-2,2,5 }
These are spill formulas so you only need to put it in one spot and it will expand the formula over the adjacent cells below where it's entered for however many cells needed to list all the unique numbers that occur. It takes into account the negatives and so on. This may be a 365 formula, so if you're on another version of excel it may not work.
Edit: Adjusted the instructions to fully address the question.
I have a sheet with transactions. Each txn has an airport and an amount of fuel pumped. I have a second sheet with a list of locations, each row of which has min and max values for fuel bands (e.g, 1-500, 501-1000, min/max stored in separate columns), and each each of which have a price (for fuel per gallon).
I need to use the values per row in the first spreadsheet to search the second spreadsheet for a match on airport (ICAO code), greater than bottom of band, and less than top of band, and then return the unit price of fuel. The catch is that I can have multiple matches, and I need the smallest/lowest value.
I have some familiarity with Index/Match multi criteria arrays. So, I wrote the following and tried it:
=INDEX(FuelPrices!$D$2:$D$3398,MATCH(1,(FuelPrices!A:A=H2)*(FuelPrices!B:B>=N2)*(FuelPrices!C:C<=N2),0))
Where "Fuel" is my first sheet and "FuelPrices" is the sheet I'm looking up the values in. No matter WHAT I do it throws an #NA error. So, I figured maybe the problem was I was returning an array? I tried this:
=INDEX(FuelPrices!$D$2:$D$3398,SMALL(MATCH(1,(FuelPrices!A:A=H2)*(FuelPrices!B:B>=N2)*(FuelPrices!C:C<=N2),0),1))
Figuring it would give me the smallest value from the returned array. No go. I've tried some other tricks (using another Index function around the match) and nothing seems to work.
Basically I just want to get the function to return the lowest matching value for the provided criteria.
The short answer is that the < and > are the wrong way round. This does give an answer
=INDEX(FuelPrices!$D$2:$D$10,MATCH(1,(FuelPrices!$A$2:$A$10=H2)*(FuelPrices!$B$2:$B$10<=N2)*(FuelPrices!$C$2:$C$10>=N2),0))
if entered as an array formula using CtrlShiftEnter
I have changed all ranges to a small number of rows for testing purposes.
FuelPrices sheet
Fuel sheet
If you do want to find the smallest subject to the same conditions, you don't need index but can use small (or min)
=SMALL(IF((FuelPrices!$A$2:$A$10=H2)*(FuelPrices!$B$2:$B$10<=N2)*(FuelPrices!$C$2:$C$10>=N2),FuelPrices!$D$2:$D$10),1)
Or if you prefer you can use Aggregate (non-array formula)
=AGGREGATE(15,6,FuelPrices!$D$2:$D$10/((FuelPrices!$A$2:$A$10=H2)*(FuelPrices!$B$2:$B$10<=N2)*(FuelPrices!$C$2:$C$10>=N2)),1)
This is what I am trying to figure out:
IF date in cell matches dates in range
and
If name in cell matches names in range
then
count/sum the number of unique ID#s
This is the formula I have:
=IF(Data!A:A=E10,(IF(Data!D:D=D11,(IF(Data!D:D=D11,SUM(IF(FREQUENCY(Data!C:C,Data!C:C)>0,1)),"ERROR3")),"ERROR2")),"ERROR1")
It does not output the correct info. It either counts all the unique IDs or it Errors out when it should have a result.
I hope I am on the right track, thank you for any help.
Sample dataset:
Try it as,
=SUMPRODUCT(SIGN((B$2:B$10>=E2)*(B$2:B$10<=F2))/
(COUNTIFS(B$2:B$10, ">="&E2, B$2:B$10, "<="&F2, A$2:A$10, A$2:A$10)+(B$2:B$10<E2)+(B$2:B$10>F2)))
First let me say that the question was pretty confusing before you posted an image of the data, as it appears that the term "dates in range" was completely misleading. In fact you are trying to match exact dates, not "ranges of date".
FREQUENCY is useful to detect the first appearance of an item in a column, but unfortunately, this "artificial trick" is not flexible enough to be mixed easily with other criteria, and most importantly FREQUENCY is not array friendly.
There's another method to achieve you goal, which is:
=SUMPRODUCT(((Data!$A$1:$A$24=E$10)*Data!$C$1:$C$24=$D11))/
COUNTIFS(Data!$A$1:$A$24,Data!$A$1:$A$24,Data!$B$1:$B$24,Data!$B$1:$B$24,Data!$C$1:$C$24,Data!$C$1:$C$24))
You can enter this formula in E11 in your sample image and copy/paste in the whole matrix.
The denominator of the formula (the second line) generates an array that counts for each row the number of duplicates.
The numerator sets the criteria. Since each successful row will repeat as many times in the numerator and in the denominator, each matching row will be counted for a total of one.
As a result, we obtain the number of "unique rows" that match the criteria.
The formula should not use complete columns such as A:A etc, make the effort to limit it to a reasonable number of rows, say A1:A999 or so. Complex formulas involving arrays must avoid as much as possible entire columns.
So I am trying to create a spreadsheet at allows a character in game to total the party inventory.
I am trying to sumif multiple columns based on the same criteria.
So say I am trying to sum all the rope they have.
In column A is the Item descriptions
In columns B-E are the different totals for each party member (one column per person)
Each party member has 50 rope, so I am expecting 200 rope.
I have used this formula:
=SUMIF(A:A,"Rope: Hemp",B:E) and it is only returning 50 as a value, If I utilise cell values (A1:A100 etc.) it returns a value of Zero.
I have been told that Sum Product could works so I also tried that:
=SUMPRODUCT((A1:A100="Rope: Hemp")*(B3:E100)) and I still get the incorrect result.
What am I doing wrong?
EDIT:
Here are some photos.
Here is my Raw Data. As you can see I have the inventory and tallies, when you look at rope it says 150, and this was calcualted by summing the B to E cells, however as the list is going to move and grow I thought SUMIF would be better.
As stated above, I have used a SUMIF making the range Columns B through E, and it only returns a value of 50 (I'm assuming Column B)
so came up with this:
=SUMIF(A3:A40,"="&J17&"",B3:B40)+SUMIF(A3:A40,"="&J17&"",C3:C40)+SUMIF(A3:A40,"="&J17&"",D3:D40)+SUMIF(A3:A40,"="&J17&"",E3:E40)
Which works, but I can only assume that sumif only work with ONE target range... And I tried curly brackets as well...
So, I did also use cell J17 for the object you are looking for, so you can drag it down, the "*" will find all occurences of "Rope: Hemp", or "Rope: Nylon" etc. I get a total of 150 as there are only 3 characters with rope...
Hope it helps. Someone else may have a better / neater suggestion!
I just tested it by entering Rope, rapier and rations into J17 and got the results I expect.
Image of spreadsheet: