countif excel with value in column A or column B - excel

I want to use COUNTIF in Excel, but I want to count rows where column V = yes OR column U = yes, with all the other criteria the same.
It is easy to use or with values in 1 column, such as P4:P999 = "apple" or "orange", but how to use or over multiple columns?
Below is an Excel code sample written to be readable. The only solution I found was to use addition and rewrite the entire code, but I hate this solution because it is too long.
SUM(COUNTIFS(
P4:P9999, {"apple", "orange"},
B4:B9999, "potato",
AF4:AF9999, "",
V4:V9999, "Yes"
)
) +
SUM(COUNTIFS(
P4:P9999, {"apple", "orange"},
B4:B9999, "potato",
AF4:AF9999, "",
U4:U9999, "Yes"
)
)

Switch to SUMPRODUCT:
=SUMPRODUCT(((P4:P9999 = "apple")+(P4:P9999 = "orange"))*(B4:B999="potato")*(LEN(AF4:AF999)=0)*((V4:V9999="Yes)+(U4:U9999="Yes")>0))

Related

Excel - Is there a way to tell a cell to use a certain function based on the first letter of a another cell?

I am creating a Product Decoder for a project.
Lets say, Our product can have a code such as "ABCDE" OR a code like "BCDEF".
ABCDE has a table of data that I use to decode using a lookup. For example AB can decode into "Potato" and CDE can decode into "Chip". So any combination with AB can be Potato "Anything else".
BCDER, BC can decode into "Veggie" so DER can code into "Chip".
I also use the 1/search method to take placements for the decode. Example =IFERROR(LOOKUP(2,1/SEARCH($E$19:$E$23,N18),$E$19:$E$23), "")
I concatenate all the decodes using =S2&" "&T2&" "&U2&" "&V2
Question is...if we are getting a huge amount of product code coming that I want to decode into one single column... How do I tell excel to use this table of data for ABCDE if product starts with "A", if not, use table of data that correlates to BCDER when product starts with "B".
Edit 1:
Here is my table, right side is where i look up the Part Number column N"
As you can see on column "W" I concatenate the date is Look up from columns O~V.
Column O Function: =IFERROR(LOOKUP(2,1/SEARCH($C$1:$C$7,N2),$C$1:$C$7), "")
On column N, I have two parts. One that starts with M and one that starts with K which is pretty standard.
Image two is me trying to use the IF Left but, it doesn't really work
=IF(LEFT(AA4,10) = "M ", W2, W18)
So How can I tell my excel page to use Table A1:A12 if part starts with "M*" and vice versa?
Let me know if this is confusing, I will do my best to clear things up.
First, a possible correction
I think this function does not give you what you say it does:
= IFERROR(LOOKUP(2,1/SEARCH($E$19:$E$23,N18),$E$19:$E$23), "")
You might mean:
= IFERROR( LOOKUP( 2, 1/SEARCH( $E$19:$E$23, N18 ), $F$19:$F$23 ), "" )
Because you want to look up the value in column E and return the value in column F. If that's not true, then skip the rest of this answer.
Now the solution
What you're trying to do is change the lookup array if the part number starts with a different letter. So, the IF( LEFT( combo mentioned by #BigBen should be used to modify the lookup array. I think it would look like this:
= IFERROR( LOOKUP( 2
,1/SEARCH( IF( LEFT( AA4, 1 ) = "M"
,$C$2:$C$12
,$C$19:$C$23 )
,N2 )
,IF( LEFT( AA4, 1 ) = "M"
,$D$2:$D$12
,$D$19:$D$23 )
)
,"")

How to do a quadruple IF in excel

I would like to make an IF statement in Excel where if a certain cell equals to O, V, G or U another cell outputs 1, 2, 3 or 4 respectively.
I can't find any solution only, sorry.
There's probably a cleaner way to do this... but I'm not an excel expert.
If A1 is the cell you are checking to contain O V G or U:
=IF(A1="O", 1, IF(A1="V", 2, IF(A1="G", 3, IF(A1="U", 4, ""))))
The syntax of excel's if is: If(condition, valueIfConditionIsTrue, valueIfConditionIsFalse)
This is how excel interprets the command in a way that's easier for us to understand:
if A1 == "O":
output = 1
else:
if A1 == "V":
output = 2
else:
if A1 == "G":
output = 3
else:
if A1 == "U":
output = 4
else:
output = ""
I think the easiest solution would be to create a look up table and then use a combination of the INDEX MATCH functions to grab the appropriate value. You can read more about INDEX MATCH here: https://exceljet.net/index-and-match
To start, create a table similar to this:
Then assuming you have a list of letters you are trying to match you can write a formula similar to this: =INDEX(Table1[Output],MATCH(E3,Table1[Letter],0)). If you want the formula to return blanks "" instead of #N/A, you can wrap the formula in an IFERROR:
=IFERROR(
INDEX(Table1[Output],MATCH(E3,Table1[Letter],0))
,"")
Here's a picture of the final output.

EXCEL 2010 sum with multiple column criteria range in an OR logic

In Excel 2010, I have to table which have 5 columns and data shown in the picture
.
The rule is basically once someone’s name is in one of the three columns [Edit, Translation or Final Edit], I should add the Word count to them. But if the same name is in 2 of those columns, the word count should be added just once.
Is there a way to count how many words that each person have processed? Thanks.
Use SUMPRODUCT:
=SUMPRODUCT(--(($C$2:$C$13 = G7)+($D$2:$D$13 = G7)+($E$2:$E$13 = G7)>0),$B$2:$B$13)
Yes you can do it...Lets say you have a date like 2-Nov-2018 for entries...Change your output table and replace "Total Word COunt" by month name i.e. "Nov" and use below formula :
=SUMPRODUCT(--(($C$2:$C$13 = G9)+($D$2:$D$13 = G9)+($E$2:$E$13 = G9)+(TEXT((F4:F15),"MMM")=H8)>0),$B$2:$B$13)

Power BI - I need a "countif" formula to look at unique entries in row/column

I have only been working in Power BI for a little over one week now, and now I have run into my first problem..
I need a way to do the same as in below Excel formula..
In Power Bi I have ONE table.
I want to count unique "Split Orders" in column "B"
But I only want to count them once..
So the first time it is found, it is counted as 1
Next I see it it is counted as 2 or 3 or 4 or more..
So formula says "if counted MORE than once, then return "X", else return "1"
And the IF statement then says if higher than 1, return 0 else return 1
I have many thousands of rows and I need to identify each as either unique or not..
But I can't seem to find the right combo of DAX formulas to do so.
I have looked at COUNTDISTINCT, CALCULATE, FILTERS, COUNTROWS, and many more.
They might be the right ones to use but I haven’t managed to find the right syntax.
Many of the DAX formulas I have tried, either return ONLY "1" or ONLY "0" or they return the total amount of unique orders..
Excel formula:
Row 2 = IF(B2="";0;IF(COUNTIF(B$1:$B2;B2)>1;0;1))
Row22 = IF(B22="";0;IF(COUNTIF(B$1:$B22;B22)>1;0;1))
Row32 = IF(B32="";0;IF(COUNTIF(B$1:$B32;B32)>1;0;1))
What you are looking for is a Calculated Column and not a Measure. Also you need to determine the order in which the [Split Order] column should be read.
You can do this by adding an index column in Power Query (Add Column tab). After doing that, add this Calculated Column:
IsFirstOccurence =
IF (
COUNTROWS (
FILTER (
'table',
'table'[Split Order] = EARLIER ( 'table'[Split Order] )
&& 'table'[Index] <= EARLIER ( 'table'[Index] )
)
) = 1,
1,
0
)
The result looks like this:

keeping a running sum of a formula with conditions

I am having an issue with an excel problem and cannot use vba or add any extra columns. The problem goes along with the format of this image. I could not find anything on google that helped me with this problem and im sorry if it has been asked before.
Example Image
On a separate page in a cell i need to write a function that will check if Info 2 = "z" and Info4 = "x" and if that is true then i need to do the following equation with the numbers in Info1 and Info3: Info1*(1 - Info3)
I will also have to keep a sum of these numbers.
For this example I would want the cell with the formula to equal -34 by doing the following:
3*(1-4)+5*(1-6) = -34
I would want the cell to just display the finished sum
Any help would be greatly appreciated,
Thank you!
You are looking for the mighty powers of SUMPRODUCT
=SUMPRODUCT((B:B="z")*(D:D="x")*(A:A)*(1-C:C))
The first two multipliers will make sure we only evaluate those rows having z for B and x for D. While the latter two are your desired function. Excel will evaluate this for each row and sum up the results.
I am using psuedo values below but this should work:
= [value of cell above] + if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
so basically starting in the middle, you have a two truth tests,
[info2] = "z", [info4]= "x"
using AND() requires they both pass
and([info2] = "z", [info4]= "x")
if they do pass you want to do your formula:
if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),FALSE)
but since we want to sum all values for each iterative row we make not passing this test 0:
if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
Ok so this works for one row, but doesn't sum the numbers from the tests on the previous row:
= [value of cell above or 0 for first row] + if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
an example written with real excel ranges that you may have to tweak depending on where your values are stored:
Sample picture

Resources