Excel CountIF nested in IF function - excel

I have a dashboard I'm trying to put together and I don't understand how Excel is interpreting my formulas. I'm trying to get excel to read a cell that contains a month value, and if that value is true, then to read my dummy variables and count them. There is multiple criteria here so I used CountIFS.
Here's how the function works
=IF('Other tab'!$AI:$AI=B3,COUNTIFS('Other tab'!$BI:$BI,1,'Other Tab'!$BB:$BB,1,'Other tab'!$BC:$BC,1),"ERROR")
where any place there is a "1" there was a dummy variable created. I also tried to do this with the actual text that the dummy variables replaced and my formula still wouldn't work. I don't get an error, but the return value is "0"
Here's a sample of the data:
Current Tab:
1 A B C D E F G H
2
3 Metric January February March April May June July
Other tab:
AI BB BC BI
1 January 0 1 1
2 January 0 1 1
3 January 0 0 0
4 January 1 1 1
5 January 1 1 1
6 December 1 1 1
According to my formula, "3" should be the result here.
Update: I switched the formula to read the "0"'s on my dummy variables instead of the "1"'s and it worked to retrieve that, so why isn't it working when specifying "1" as my countif criteria?

There is no reason to put the first part in an IF statement just add it as criteria to the COUNTIFS:
=COUNTIFS('Other tab'!$AI:$AI,B3,'Other tab'!$BI:$BI,1,'Other Tab'!$BB:$BB,1,'Other tab'!$BC:$BC,1)
It appears that your data not consistent. You are looking for a text string in a series of dates that is formatted mmmm. To deal with this, in another column on the Other tab put this formula:
=TEXT(AI1,"mmmm")
And copy down.
Then change the 'Other tab'!$AI:$AI part in the above formula to new column in which you just put the 2nd formula.
This will now allow the comparison of text to text.

Related

If function and Xlookup

I am currently trying to run an excel function that runs the logic that if the cell that has date X is greater than date 2023-01-01 then run an XLookup function. If it is not then do not run it.
Here's what I tried below:
=IF(table2!N5>DATE(2023,1,1),XLOOKUP(A2,'Table2'!A:A,'Table2'!B:B),"FALSE")
N5 has the date 2022-12-01. The rest is just a standard xlookup function that would run if cell N5 is greater than the date 2023-01-01.
Data for the Xlookup below:
Table 1 : This table provides the lookup value A1.
A B C
1 Position Classification Full Name
2 111111 IT 04 John Smith
Table 2 : This table provides the lookup array being A:A and the return array being B:B
A B C D
1 Employment Position CC Valid From Valid To
2 111111 8888888 2022-10-01 2023-03-31
As posted in comments, I will suggest you use a cell reference, so it becomes more dynamic to use, instead of hard coding within a formula,
• instead of this
=IF(N5>0+"2023-01-01",XLOOKUP(E3,H:H,J:J),"FALSE"))
• Use a cell reference, let's say cell A1 = 2023-01-01
=IF(N5>A1,XLOOKUP(E3,H:H,J:J),"FALSE"))
So the above helps you in changing the cell A1 values whenever you need instead of bothering the formula each time for a change.
I would advise you to use the DATE() function, like this:
= IF(A1>DATE(2023,1,1), ...)

Excel counting cells based on complex criteria

Hate asking question about something as simple as an Excel formula, but seem to really need and would appreciate the help.
I have a table where the rows headings contains names and the column headings contains week numbers. Within this table I have differents numbers. Both numbers that are plus and negatives.
I want to count each cell where the row heading matches a specific name and then each cell that has a plus value with a week number less than or equal to a certain week.
I have tried to got it to work with at least some function (without it caring about plus and negative values) but haven't even gotten that to work.
I've tried with:
=SUMPRODUCT((Data!F3:F28=I1)*(Data!I2:BI2="<="&A1)*(Data!I3:BI28))
=SUMIFS(Data!I3:BI28;Data!F3:F28;I1;Data!I2:BI2;"<="&A1)
.............1 2 3 4 5
name1 -1 4 3 1 1
name2 0 0 0 0 0
I want a formula that counts for example every column header with a value less than or equal to (for example) 4, but excludes negatives and vice versa. So for the example above, the result of name1 should be 8; counts week 2, 3 and 4.
For your current example:
Formula in H3:
=SUMPRODUCT((B2:F3>=0)*(B1:F1<=4)*(A2:A3="name1"),B2:F3)

In Excel how to count between date1 and date2 that have cells in row that contain text?

I need to choose cells in one column that are between two dates, and then based on the rows that contain those dates, choose cells in another row that also contains content.
I didn't use ISBLANK because it counts a formula yet an empty cell as a not-blank. Instead check if there is content by "*".
Here is what I came up with, but instead of returning the number of cells, instead this returns TRUE (which obviously isn't what I want).
In the formula below I am assuming:
C:C is the whole column containing DATES.
E:E is the whole column containing CONTENT.
The date range in this case is January 1, 2018 to January 31, 2018.
"*" means is there is content in the cell
=IF(AND(COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&"2018-1-31"),COUNTIF(E:E,"*"))=0,"",AND(COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&"2018-1-31"),COUNTIF(E:E,"*")))
My goal is to:
count the numbers of the cells in column E that are between the dates in column C
if the whole formula is 0, then return a blank.
See this picture of a sample excel sheet to make my intent clear:
How can I get my formula working so it does as needed?
SOLUTION
Hi all, so thanks to #girlvsdata, we have a working solution. I had to do a couple edits to her code to work for my uses, but her formula overall works perfect. Here is the solution:
To choose all cells in column E that are not blank, in between the date range of all of January (unknown end date) based on the adjacent C column if that is your date column, then the solution is:
=IF(COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&EOMONTH("2018-1-1",0),E:E,"*")=0,"",COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&EOMONTH("2018-1-1",0),E:E,"*"))
Note that "2018-1-1" is January 1 2018, and EOMONTH("2018-1-1",0) is the last valid day of January in the year 2018 (in this case, 31, but if it is different another year (e.g. for February this works for leap years too) then it will be that last day). Also it eliminates the need to calculate which is the last day or every month, as well as months that have changing end dates dependent on the year (e.g. Feb). This is important to eliminate a margin of error.
The only thing you have to do to change the month is only change e.g. -1- (Jan) to -2- for Feb, or change the year for other years. With this formula you can ignore the day part.
If the answer is 0 (no cells have any content in between the range), then the cell is blank instead of 0. (GOod for when you want to create a sheet checking future dates for future reference when more rows are added to the sheet.
It also works across different sheets, just use, say your other sheet is called "Tracker" then use Tracker!C:C and Tracker!E:E. Hope it helps!
Thank you all! :D
(Please note: My local date format is day, then month)
With the data laid out as in your example above:
A B
1 Dates |Content
------------+-------
2 1/01/2018 |
3 2/01/2018 |123456
4 3/01/2018 |
5 4/01/2018 |12398
6 5/01/2018 |484
7 6/01/2018 |1538
8 7/01/2018 |
9 8/01/2018 |
10 9/01/2018 |
11 10/01/2018 |14648
12 11/01/2018 |
13 12/01/2018 |145615
14 13/01/2018 |
And with the date range in cells D2 and E2:
Date Start Date End
2/01/2018 7/01/2018
This formula returns the count:
=COUNTIFS(A:A,">="&D2,A:A,"<="&E2,B:B,">0")
This will depend on whether your numbers in Column B are formatted as text or number. If they are formatted as numbers, the above formula will work. If they are formatted as text, replace the last section ">0" with "*".
This formula adds the conditional part of your question:
=IF(COUNTIFS(A:A,">="&D2,A:A,"<="&E2,B:B,">0")=0,"",COUNTIFS(A:A,">="&D2,A:A,"<="&E2,B:B,">0"))
(If the formula returns 0, show blank)

Excel, How to write a formula that fits these criteria

A B C D E F G
1 Date: 9/15/2016 9/16/2016 9/17/2016 9/18/2016 9/19/2016 9/20/2016
2 Points: 0.5 1 - - 0.5 1
The above data is on tab 1 of an excel spread sheet
And below are fields on tab 2 of the same excel spread sheet:
A B
1 DATE: Points
2
3
4
5
I am trying to write a formula that will go through the dates and points rows on tab 1 and when it finds a date with a corresponding point it will populate that date in tab 2 under the Date column. Simple enough right? Well here's where I'm running into problems, I need a formula to include the following criteria:
1) If the date does not have a corresponding point in the second row on tab 1 it will skip it and move on to the next date to validate it and so on
*note- I also need the Points column on tab 2 to populate with the corresponding date, but I believe a simple HLOOKUP formula will work just fine
2) I would like to have the formula to where it can be duplicated on tab 2 cells A3,A4,A5 and so on, but as an example: if A2 has date of 9/15/2016, when the formula in A3 is checking for dates with corresponding points in tab 1, it will skip the date in tab 2 located in A2 since it's already been used
Below is a picture of the above data in case it didn't come out right, and thanks for the help!!
Use this array formula:
=IFERROR(INDEX('Tab1'!$B$1:$G$1,MATCH(1,('Tab1'!$B$2:$G$2<>"")*(COUNTIF($A$1:A1,'Tab1'!$B$1:$G$1)=0),0)),"")
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter when exiting edit mode instead of Enter. If done correctly then Excel will put {} around the formula.
This will create a list as it is dragged/copied done. The list will be in the same order as the list on tab1.

Convert some cells in a column from date format to text

Given a column like this:
Column A
1 4
2 Blank
3 Blank
4 3
5 blank
6 2NDF
7 Blank
8 blank
9 1/2/2014 <-- Date value I need to change to a text value: "1-2"
10 blank
11 5/1/2014 <-- Date value I need to change to a text value: "5-1"
12 blank
...
I need to find a way to programmatically change each cell that contains a date value like in rows 9 and 11 into a text value the equivalent of the numeric month followed by a dash follwed by a numeric day. I have 24,000 rows. Doing a find and replace is not practical. I cannot change the format of the entire column because rows like 1 and 4 get converted and I don't want those to get converted.
Create a new column B and use the function
=IF(NOT(ISERROR(DATEVALUE(A1))),MONTH(DATEVALUE(A1))&"-"&DAY(DATEVALUE(A1)),A1)
OK, I achieved the result I wanted by splitting out three "if" tests (similar to what Brett suggested) into 3 additional columns. Each column had its separate "if" test and built on the column before it. Here are the if tests:
=IF(N5>40000,MONTH(N5)&"-"&DAY(N5),N5) # sets format I want and skip cells that are low integers and not dates
=IF(O5=0,"",O5) # Sets cells with "0" in them to blank
=IF(ISERROR(P5),N5,P5) # fixes cells that were originally text and that produced errors
Given that in the OP the data seems to be in ColumnA starting in Row1 a single formula such as:
=IF(OR(A1<40000,ISTEXT(A1)),A1,MONTH(A1)&"-"&DAY(A1))
and copied down would seem adequate.

Resources