Excel formulas - count based on two criteria - excel

I've been struggling to get this formula to work. I have a spreadsheet where I need to find out how many of one column (BH2:BH915) contain a value (X) if another column (N2:N915) contains either 1 or 0. I've tried a bunch of versions to get it to work - this is the latest:
=sum(countifs(N2:N915="1","0") and (BH2:BH915="X"))
Can anyone tell me where I'm going wrong?

You'll need to add together the count of records with 0 and X and the count of records with 1 and X
=COUNTIFS(N2:N915, 0, BH2:BH915, "X") + COUNTIFS(N2:N915, 1, BH2:BH915, "X")

You could also use
=SUM(COUNTIFS(BH2:BH915,"x",N2:N915,{0,1}))
or if you knew that the numbers in N2:N915 were integers
=COUNTIFS(BH2:BH915,"x",N2:N915,">="&0,N2:N915,"<="&1)

Related

Replacing if/if with if/and returns false (Google Sheets / Excel)

I need cells on Sheet_2 to return a specific value from Sheet_1 (column K) on the condition that the values in other particular cells on Sheet_2 match with cell values on Sheet_1. I already have a pre-made formula that works, but I wanted to change it (I'm still learning Excel and trying stuff out) by replacing IF(IF..)) with IF(AND(..)).
However, the second formula returns 0, and I don't understand why. I think there is a problem with the SHEET_1 references, but I don't know what this problem is.
I've been at it for like 2 hours, so any help would be very appreciated
Works:
=ARRAY_CONSTRAIN(ARRAYFORMULA(SUM(IF(
'SHEET_1'!$L$2:$L$300=I$2;
IF('SHEET_1'!$A$2:$A$300=$Z3;
IF('SHEET_1'!$G$2:$G$300=$A3;
IF('SHEET_1'!$H$2:$H$300=$C3;'SHEET_1'!$K$2:$K$300); 0))))); 1; 1)
Doesn't work:
=ARRAY_CONSTRAIN(ARRAYFORMULA(SUM(IF(AND(
'SHEET_1'!$L$2:$L300=J$2;
'SHEET_1'!$A$2:$A300=$Z3;
'SHEET_1'!$G$2:$G300=$A3;
'SHEET_1'!$H$2:$H300=$C3); 'SHEET_1'!$K$2:$K300;0); 0))))); 1; 1)
try:
=ARRAY_CONSTRAIN(ARRAYFORMULA(SUM(IF(
('SHEET_1'!$L$2:$L300=J$2)*
('SHEET_1'!$A$2:$A300=$Z3)*
('SHEET_1'!$G$2:$G300=$A3)*
('SHEET_1'!$H$2:$H300=$C3); 'SHEET_1'!$K$2:$K300;0); 0))))); 1; 1)
within Sheets you can try:
=SUM(IFERROR(FILTER(SHEET_1!K:K;SHEET_1!A:A=Z3;SHEET_1!G:G=A3;SHEET_1!H:H=C3;SHEET_1!L:L=I2)))
OR
=ARRAYFORMULA(SUM(IF((SHEET_1!$L$2:$L300=I$2)*(SHEET_1!$A$2:$A300=$Z3)*(SHEET_1!$G$2:$G300=$A3)*(SHEET_1!$H$2:$H300=$C3); SHEET_1!$K$2:$K300;0);0))

Identify overlapping configurations in Excel

I'm setting up a configuration excel sheet to be imported into a database.
It has four columns
Equipment Fleet Start Date End Date Highlight Me
=============================================
A X 1-Jan-20 5-Jan-20 X
A Y 6-Jan-20
B C 1-Jan-20 3-Jan-20
B D 4-Jan-20 10-Jan-20
A Z 3-Jan-20 X
A Z 5-Jan-20 X
I need to identify and highlight overlapping configs
I'd like lines 1, 5 and 6 to be highlighted.
They are all a configuration for the same Equipment, but their configuration dates overlap
Fleet is that attribute we are configuring for the date range but has no bearing on the validation
Constraints:
I'd like to use tables (not named ranges) for this. My table is called tblFleetConfig
Yes I could do this in VBA but I don't want to deal with trusted workbooks etc. etc.
So far I have pasted this into a column on the right
=
(tblFleetConfig[#[Start Date]] >= tblFleetConfig[Start Date])
*
(tblFleetConfig[#[Start Date]] <= tblFleetConfig[End Date])
*
(tblFleetConfig[#Equipment]=tblFleetConfig[Equipment])
The result I'm getting is a 1 for the first line and 0 for every other line.
Clearly I don't understand this syntax and I'm interested in learning.
You asked a complicated one, those blanks throw a wrench into it.
Your formula is the right syntax, you need to wrap it in a SUMPRODUCT() though.
=SUMPRODUCT((tblFleetConfig[End Date]<=tblFleetConfig[#[End Date]])*(tblFleetConfig[Start Date]>=tblFleetConfig[#[Start Date]])*(tblFleetConfig[Equipment]=tblFleetConfig[#Equipment]))
This is your formula wrapped it in a SUMPRODUCT().
This will return a 1 if there is a single occurrence and a number greater than 1 if multiple.
Let me know if it works.

Excel sum based on matrix condition and multiple criteria

Following from the example here I'm trying to add additional conditions to a sum formula. I've represented an example below:
The output that I'm looking for for example for Jan 2017 is
2017
1
UP A 1
UP B 6
UP C 6
DOWN A 1
DOWN B 8
DOWN C 7
I tried with the following formula:
=MMULT(--($B$17:$C$17="X"),MATCH(1,($A23=$C$2:$C$14)*(C$21=$A$2:$A$14)*(C$22=$B$2:$B$14)*($E$2:$E$14=$D$2:$D$14),0))
but I get a N/A value.
Does anyone know it if is possible to do it?
In your first example the number of rows in array1 and number of columns in array2 were equal, five. Here you have two columns and 13 rows. That they are unequal here is part (all) of the reason why you are having an issue.
Also your match function is returning a Boolean not an array
I have a way to do this using matrix condition and multiple criteria but had to change problem up a bit, see photo for example:
{=MMULT(--(D18:P18="x"),E$2:E$14*(--(A$2:A$14=$C$21)*--(B$2:B$14=$C$22)*--(C$2:C$14=A24)))"
https://i.stack.imgur.com/FEvgR.png
You can create a formula to fill the second matrix with X's see below
=IF(OR(INDIRECT("D"&VALUE(D20))=$A$18,INDIRECT("D"&VALUE(D20))=$B$18),"X","")
https://i.stack.imgur.com/4rS4L.png
That being said I don't think this is particularly efficient as you are treating the one of the matrixes as a all 1's so you basically just adding an extra criteria / Boolean with added complexity....that being said u asked for this specifically and I believe that I have delivered that LOL
Just add two SUMIFS together.
=SUMIFS($E$2:$E$14, $A$2:$A$14, C$21, $B$2:$B$14, C$22, $C$2:$C$14, $A23, $D$2:$D$14, IF(INDEX($B$17:$C$19, MATCH($B23, $A$17:$A$19, 0), 1)="x", $B$16))+
SUMIFS($E$2:$E$14, $A$2:$A$14, C$21, $B$2:$B$14, C$22, $C$2:$C$14, $A23, $D$2:$D$14, IF(INDEX($B$17:$C$19, MATCH($B23, $A$17:$A$19, 0), 2)="x", $C$16))

Excel: Countifs on Multiple Columns and Only on Visible Rows (Filtering)

I've seen several forum posts with the answer to this question, but I can't really understand how it's supposed to work, so I figured I'd come here for an explanation.
I have three columns:
CITY........|.Attribute 1.|.Attribute 2.|
Chicago..|........1........|........1........|
Chicago..|........1........|..................|
Boston....|........1........|........1........|
Chicago..|..................|..................|
Boston....|..................|..................|
Boston....|..................|........1........|
Chicago..|........1........|........1........|
Chicago..|........1........|........1........|
I want to get a count of the number of times a city has a "1" in Attribute 1 and Attribute 2. Normally, you would use COUNTIFS (=COUNTIFS(B2:B9,"1",C2:C9,"1"))which would give you the value of 4 - Rows 2, 4, 8, and 9.
But I want to be able to filter this list on the fly, and only be able to see data for Chicago rows, for instance. And thus, want to see the value of 3 - Rows 2, 8, and 9. But when the data is filtered, I still get the value of 4.
What code do I need to insert into my cell to get the value of 3 after filtering my list to only show Chicago, if I want to see when a city has a "1" in both Attribute 1 and Attribute 2?
Thanks!
Would this not work for Chicago?:
=COUNTIFS(A2:A9, "Chicago", B2:B9,"1", C2:C9, "1")
This would not require you to filter the data.
A variant of this could be used:
SUMPRODUCT((Attribute 1.=Satisfactory)*(SUBTOTAL(103,OFFSET(AW3,ROW(tblStudentProgress[D3 Activity])-MIN(ROW(tblStudentProgress[D3 Activity])),0))))
You could also create a helper column and sum attributes 1 and 2. If your helper column row equals 2 then you know both attributes exist. You could take this one step further and use concatenate to combine "Chicago" and your sum. And then filter by Chicago2.

Using VLookUp for a partial search

I have two tables in excel.
In table 1, one column contains a list of order numbers. This is done the format of XXXX-YYYY where X is an integer and Y is a letter. For example 3485-XTIP
Table 2 also has an order number column but this time it's in the format XXXX-YYYY (ZZ) where Z is the initials of the customer who made the order. Example: 3485-XTIP (KN)
How can I use a VLookUp to search for the order number in Table 2 but only using the XXXX-YYYY part? I tried using TRUE for an approximate search but it still failed for some reason.
This is what I have
=VLOOKUP("I3",'Table2 '!A:B,2,FALSE)
I am open to any alternatives other than VLookup for this situation.
Note that there are hundreds of order numbers and entering the strings manually will take forever.
You can use * as wildcard and add it at the end of the order number so that your VLOOKUP will match any order plus any other characters that come after it:
=VLOOKUP(I3&"*", 'Table2 '!A:B, 2, 0)
* will match anything after the order number.
Note: 0 and False have the same behaviour here.

Resources