Excel formula to sum values based on reference number in another column - excel-formula

I have two columns. One is an amount and the other is a reference number. I need a formula to sum all amounts per reference number next to the reference number in order to sort from highest to lowest value per reference.
Amount | Reference | Sum per Reference
122.00 | 405221 | 316
194.00 | 405221 | 316
339.80 | 405682 | 851.25
296.45 | 405682 | 851.25
215.00 | 405682 | 851.25
The closest formula I found on this website, was:
=IF((AR2=AR3),"",SUM($AQ2:AQ2-SUM(AV$1:AV1)))
This however only puts the sum value (like a subtotal) at the last reference number and leaves the other ones blank. I need it to put the sum value for each reference number next to all the lines and have not blank spaces?

It sounds like what you're looking for is the SUMIF function. It sums values by a criterion, so in this case we can use it to sum all values that match another value. Assuming your values are in Column A and your criteria are in Column B:
=SUMIF($B:$B,$B2,$A:$A) Put this formula in your "SUM per Reference" column and copy it down, and you should get a good result.

Related

Vlookup a value and then compare dates

I am wanting to look up a value from a table, than take a date and compare it to the row and find which date corresponds to the date I enter.
| Column1 | Effective 1 | Effective 2 | Effective 3 |
|---------|-------------|-------------|-------------|
| abc | 1/1/2016 | 1/1/2017 | 1/1/2018 |
| cba | 1/2/2016 | 1/2/2017 | 1/2/2018 |
I want to look up colum1 and find for example cba; then want to link a date to which effective date, which is always the date less than. So, if the date I am looking up is for cba and it is 6/7/2017 it would correspond to effective 2 which is 1/2/17.
I have tried index match match and also vlookups with embedded if statements and neither of them work.
Using structured references (in a Table), the following formula will do what you want.
=LOOKUP(2,1/((INDEX(myTable,MATCH(F2,myTable[Column1],0),0))< TODAY()),INDEX(myTable,MATCH(F2,myTable[Column1],0),0))
The formula uses documented but somewhat obscure features of the INDEX and LOOKUP formulas. See MSDN Help for more details:
MATCH ► find the row that matches the search term in F2 to use as row argument in INDEX
INDEX with a column argument of 0 ► return the entire row
< TODAY() to do the less than comparison. You can use a cell reference instead of you need to.
1/(... will return 1 or DIV/0 errors depending on the comparison
LOOKUP where the lookup_value is greater than anything in the array will match the last numeric value in lookup_array and return the value in the same position in results_array

COUNTIF range does not equal range

The data I'm looking to get is something like this:
+----------+-------+
| Location | Count |
+----------+-------+
| Jungle | 2 |
| Ocean | 4 |
| Other | 2 |
+----------+-------+
The formula for count should look in the data range and if a cell's data does not equal any of the cell data in the rest of the location column (Jungle, Ocean) it should add that to the count. It should exclude blanks.
This is the formula I tried:
=COUNTIF(A1:H6,"<>"&E11:E12)
Here is my example sheet: https://docs.google.com/spreadsheets/d/1YbqEwa3olEXMcmU-UORfe7jwyK_-AXDomp1t5iTVUaU/edit?usp=sharing
Where am I going wrong? There are 7 other instances of colours not Green or Blue therefore I would expect this result to be output. I haven't put anything in about ignoring spaces so I would expect the result to count blanks too, but I get 0.
Don't use & - this would join E11 and E12 together so you would be looking for greenblue. You would need a COUNTIFS to get the three conditions
=COUNTIFS(A1:H6,"<>"&E11,A1:H6,"<>"&E12,A1:H6,"<>")
Here is a more general way of doing it
=COUNTA(A1:H6)-SUMPRODUCT(COUNTIF(A1:H6,E11:E12))
See this useful reference
The COUNTIFS formula is your friend here. This formula should work for that cell:
=COUNTIFS(A1:H6,"<>"&E11,A1:H6,"<>"&E12,A1:H6,"<>")
The problem with a 'does not equal OR does not equal' is that when it is not equal to one, it could be equal to the other and vice-versa. Additionally, you range to count from is 2 dimensional so you cannot use rows of criteria. Use SUMPRODUCT and individual criteria multiplied against each other.
=SUMPRODUCT((A1:H6<>"")*(A1:H6<>E11)*(A1:H6<>E12))
Any of those three conditions that is not true is considered zero. Anything multiplied by zero is zero. 1 x 1 x 1 is 1.
For large numbers of exclusions, you will want to use an array formula (with CSE) to count them and then subtract that total from a COUNTA total of the entire range.
=COUNTA(A1:H6)-SUM(COUNTIF(A1:H6,E11:E15))

Use Excel SUMIF to add cells with custom number formatted dollar value

I have a range of cells that contain dates and dollar amounts. I'd like to total the cells with dollars.
The worksheet is formatted in columns like this:
Date | Amount |Date | Amount | ... for about 20 col.
| | | |
| | | |
| | | |
I've tried various versions of SUMIF but I can't get a formula that will ignore the dates and include the dollar values. The dollar value cells have a custom number format that includes a $ sign. But I haven't been able to get anything that can use the $ to distinguish the 2 types of cells. Any suggestions?
The actual numerical value may be useful but it will depend upon the nature of your data (which is conspicuous by its absence).
A day is 1. A Date is 1 for every day past 31-Dec-1899. Today happens to be 42,537 and one year ago was 42,171. If no valid amount was larger than $40,000 then you can reliably use the SUMIF or SUMIFS function by discarding numerical amounts greater than EDATE(TODAY(), -12).
=sumif(a:z, "<"&edate(today(), -12), a:z)
=sumifs(a:z, a:z, "<"&edate(today(), -12))
Note the syntax differences between SUMIF and SUMIFS.
Another approach would be comparing the column header labels in a SUMPRODUCT function.
=sumproduct((a1:z1="amount")*a2:z999)
Do not use full column references with SUMPRODUCT. Always restrict your data ranges to the extents of your actual data.

Excel VLookup #NV error

I'm trying to make a VLookup in Excel but I get everytime a #NV error.
This is table EVENTS:
This is table TRACK:
the formula on field F2 in table EVENTS is
=SVERWEIS(E2;TRACKS!$A$2:$B$52;1;FALSCH)
SVERWEIS is the word for VLOOKUP in the German version. FALSCH means wrong
As has been mentioned, VLOOKUP (SVERWEIS) can only look to its right to find a value to correspond with a value in the left hand columns of a table. The INDEX/MATCH combination is more flexible in this respect so if not to rearrange your columns I would suggest something like:
=INDEX(A:A,MATCH(E2,B:B,0))
where TRACK is assumed to be in ColumnsA:B. Converting to German, perhaps:
=INDEX(TRACKS!A:A;VERGLEICH(E2;TRACKS!B:B;0))
VLOOKUP compares the values in the first column of your reference target, you have your target values in the second.
Just swap VLOOKUP and the TEXT columns on your TRACKS sheet and it will work just fine.
Try switching the columns in TRACKS around.
VLOOKUP bases it's lookup on the first column, so in your case, it's looking through column A (1, 2, 3, etc.)
If you want your VLOOKUP to be based on the text, it needs to be in A instead.
i.e.
| A | B |
----------------------
1 | TEXT | VLOOKUP |
2 | Text1 | 1 |
3 | Text2 | 2 |
etc...
Then your function will be:
=SVERWEIS(E2;TRACKS!$A$2:$B$52;2;FALSCH)
Switching out the third argument because you now want the value from the second column

Excel: Concatenate/retrieve cells that are across a merged key cell

Assume a simple sheet like so:
-------------
| 1 | a | Need formula to return: "a,b,c"
| |-----|
| | b |
| |-----|
| | c |
-------------
| 2 | a | Need formula to return: "a,b"
| |-----|
| | b |
-------------
The first column is the merged key cells and the second column has an unknown number of rows with text values in each cell.
What I want is a means, such as VLOOKUP/HLOOKUP, to retrieve a list of the cells across the merged key cell.
Even if I want to use Macros, how do I retrieve the a-b-c cell range programmatically as a result of VLOOKUP on the "1"?
If that doesn't work, I'm fine with just a logical check on whether a letter exists in the list.
For example, given a key value, I want to be able to programmatically apply conditionals like:
- "Does 'a' exist at '1'? Yes."
- "Does 'c' exist at '2'? No."
EDIT:
Keep in mind that the above is an example; I do not necessarily know that there is only 'a', 'b', and 'c'; I do not know the number of rows in each set.
Thanks.
This will give you True/False, though you can nest it in an IF statement to get Yes/No.
=NOT(ISERROR(VLOOKUP("b",INDIRECT(ADDRESS(MATCH(1,A:A,0),2)&":"&ADDRESS(MATCH(2,A:A,0)-1,2)),1,0)))
The variables are "b" which is the letter to look for, the 1 in the first match statement which is the number to key off of, and then the 2 in the second match statement is just the 1 variable +1.
The formula first determines the range of cells in column 2 for the 1 variable, by determining where it starts, and then going to one less than where the next number ends. Of course this will only work if the numbers are consecutive and ordered. It then does a VLOOKUP on the range that was determined, which for your example would be $A$1:$A$3.

Resources