Okay so here’s what I need…. And let me preface this by saying I know this can be done in a pivot table however, I am trying to avoid using a pivot table.
Col J Col M Col Q
origdest weeknum Wks Shipped - Prior 12 Months
AAABBBCCC 48 3
XXXX 44 2
AAABBBCCC 48 3
XXXX 44 2
AAABBBCCC 44 3
XXXX 45 2
YYYY 48 1
AAABBBCCC 3 3
ZZZZZ 48 1
In column Q, I need a formula that will give me the unique value in column M of the matching column J (which should give me the result shown in column Q.. In other words, I need to know how many weeks that “origdest” shipped. It seems like it should be pretty simple but I can’t seem to make anything work and I have had an issue with entering an array formula, it hangs up my computer.
There is a fairly standard method of achieving unique counts involving the SUMPRODUCT function and the COUNTIF function. Your situation demands that more criteria be introduced by substituting COUNTIF for the COUNTIFS function.
In Q2 try this standard formula.
=SUMPRODUCT(((J$2:J$99=J2)*(J$2:J$99<>""))/COUNTIFS(J$2:J$99, J$2:J$99&"", M$2:M$99, M$2:M$99&""))
Fill down as necessary. Your results should resemble the following.
Related
I want to sum the columns B-D given that column A equals "far".
Does anyone have a smooth formula for this calculation?
The answer should read : 10+10+3+12+2+5 = 42
A B C D
Far 10 10 3
Sol 10 21 12
Far 12 2 5
Sol 10 2 62
Gulf 10 4 0
SUMPRODUCT:
=SUMPRODUCT(($A$2:$A$6="Far")*$B$2:$D$6)
SUMIF:
=SUMIF(A:A,"Far",B:B)+SUMIF(A:A,"Far",C:C)+SUMIF(A:A,"Far",D:D)
Both have their advantages and disadvantages.
SUMPRODUCT is shorter formula and easier to maintain but it is an array type formula and the references need to be limited to the data set.
SUMIF is not array but it requires the ranges to be the same size and as such one must do a SUMIF for each column and then sum the results.
It seems like this question should exist somewhere, but I can't seem to find it...exactly.
The most similar solution I can find requires the use of SUMIFS or SUMIF, which only seems to add up numbers in a column, not spanning multiple columns. Here's an example sheet with 2 rows:
A B C D E F G H ...
1 2015-01-01 0 1 6 12 45 12 5 ...
2 2016-01-01 256 43 13 35 134 135 12 ...
Now I'd like to have a cell somewhere that adds all of the cells in the row for 2015-01-01. My attempt looks like:
SUMIF(A1:A30,"2015-01-01", B1:BJ30)
But this only yields the sum of the column B, so 0 for the exact formula above or 256 if I were to do this for the year 2016.
When trying something with SUMIFS, I'm told that the criterion range's size should match the sum range size, which isn't the case because my criterion range is only the first column of dates.
How can I add all the values in a row if the first cell's date matches my criterion? It may be worthwhile to note that this is in Google Sheets, not Excel.
In both excel and googlesheets you can use a SUMPRODUCT, for example:
=SUMPRODUCT((A1:A30 = DATE(2015, 1, 1)) * B1:BJ30)
You can try either of these:
=if(A1=date(2015,1,1),sum(B1:F1),"")
=if(A1=A1,sum(B1:F1),"")
I have a file with data in the following format:
text value1 value2
Given value 1 and value 2 meet some criteria, find all the unique text values.
The exact data looks like this:
john 10 20
john 15 35
mark 20 10
mark 25 15
tom 25 40
lee 16 50
If val 1 <=25 and value 2 <=35 the number of unique text = 2 (john and mark)
I have to do this using formulas not filters.
I've been trying combinations of frequency, countifs, sumproducts and a whole range of other methods and can't seem to hit what I'm looking for.
Assuming that text, value1, and value2 are in columns A, B, and C respectively ...
In D1, enter the formula =IF(AND(B1<=25,C1<=35),A1,"") and copy it down the column
Use the formula =SUMPRODUCT((D:D<>"")/COUNTIF(D:D,D:D&"")) for your answer
If you want to list the unique values rather than count them, something like this:-
=IFERROR(INDEX(A$2:A$7,MATCH(0,IF((B$2:B$7>25)+(C$2:C$7>35),1,COUNTIF(E$1:E2,A$2:A$7)),0)),"")
entered as an array formula starting in E2 ( and assuming that you are using columns A,B and C for your data.
See this reference for explanation.
The following formula will do what you are asking:
=SUM(IF(FREQUENCY(IF(B2:B7<=25,IF(C2:C7<=35,MATCH(A2:A7,A2:A7,0),""),""),IF(B2:B7<=25,IF(C2:C7<=35,MATCH(A2:A7,A2:A7,0),""),""))>0,1))
This is an array formula so confirm it with Ctrl-Shift-Enter.
I referred to this webpage.
Also found a shorter one:
=SUM(--(FREQUENCY(IF(B2:B7<=25,IF(C2:C7<=35,COUNTIF(A2:A7,"<"&A2:A7),""),""),COUNTIF(A2:A7,"<"&A2:A7))>0))
Found and modified from hre.
Lets say I have 3 columns of data
AMOUNT(A) AMOUNT(B) INVOICE(C)
55 49 4541
47 47 1515
42 47 4478
86 12 9993
12 100 1224
5 44 1452
100 4287
99 4444
What I need to check to see if the value in column A matches a value in column B. If there is a match, it will return the value from column C in column D. Now this is easy with a VLOOKUP however I am dealing with 700+ lines and there are multiple amounts that match. INDEX(MATCH) could work but it only returns one value. Is this a VB only problem?
I.E Value 47 exists in column B twice so therefore column D would return both invoice numbers (1515 - 4478)
In VBA, the problem would be trivial as you have already correctly described the logic with the problem statement itself.
Using Excel functionality only, without VBA is the interesting problem. You need to do the following steps to achieve an output that looks like this...
The steps are as follows:
Pivot Table: Make a pivot-table from the Columns (B) and (C) with Rows Fields as (B) and (C) and the minimum of AMOUNT(B) as the Value field. (See Figure below)
Helper Columns: Make a column on the side of the pivot table, say (Q) which is simply equal to everything in column (P)
Contd ... : In column (R) (which unfortunately happens to be in the sheet's column Q, sorry for the confusion there), as shown, for cell Q20 for e.g. put in the formula
=IF(P21=P20,Q21&","&M20,M20)
That will result in the creation of something like the table below:
Table:
(P) (Q)
12 9993
44 1452
47 4478,1515
47 4478
49 4541
99 4444
100 4287,1224
100 4287
Now the hard work is done. All you need to do is to lookup using VLOOKUP key-value pairs from this helper table (P)(Q)
- It will be very fast because the pivot table always keeps it sorted and hence an exact LOOKUP is not necessary.
- Screenshots are shown below for the Pivot table as well as for the final VLOOKUP formula
Pivot Table and Helper Table:
Final Formula:
so I'm using the Countif to see if there are dups based on column A.
In the D column type, =IF(COUNTIF($A$2:$A$9,B2)>0,C2,"")
I have this Data:
var number
a 1
a 4
a 30
b 4
b 50
b 6
b 4
ab 1
I need to find the sum of each time a (var occurs X the number next column right) in excel.
In the case above the answer would be:
a = 36
b = 65
How can I write a formula for this in excel? Can I do this in excel?
Since you are counting the last one as well, I would use this formula:
=SUMIF(A:A,"*"&D2&"*",B:B)
Here, there is the value a in cell B2 and I can drag the formula down for B instead of typing a whole new formula. Handy if you have many like those to look for.
I assume that you have the table you published above in cells A1:B8. In order to do the calculating you would like to do you need to use the array-functionality in Excel. The following syntax in a cell will do:
=SUM(IF("a"=A1:A8,B1:B8))
However, instead of ENTER you need to press COMMAND+SHIFT+ENTER (I am on a Mac so it might be that Windows has a slightly different key combo. The result is that the formula now reads like:
{=SUM(IF("a"=A1:A8,B1:B8))}
This will give you 35 and not 36, but in a similar manner you could sum all the columns with 'ab' and then add that up to the sum of the 'a' columns.
Good luck!