Count number of rows where multiple criteria are met - excel

I'm trying to generate a table that shows a count of how many items are in any given status on any given day. My result table has a set of Dates down column A and column headers are various statuses. A sample of my data table with headers looks like this:
Product | Notice | Assigned | Complete | In Office | In Accounting
1 | 5/5/13 | 5/7/13 | 5/9/13 | 5/10/13 | 5/11/13
2 | 5/5/13 | 5/6/13 | 5/8/13 | 5/9/13 | 5/10/13
3 | 5/6/13 | 5/9/13 | 5/10/13 | 5/10/13 | 5/10/13
4 | 5/4/13 | 5/5/13 | 5/7/13 | 5/8/13 | 5/9/13
5 | 5/7/13 | 5/8/13 | 5/10/13 | 5/11/13 | 5/11/13
If my output table were to contain a set of dates in the first column with the statuses as headers, I need a count of how many rows were at the given status and had not yet transitioned to the next status so that in the Notice column, I'd have a count of rows where the Notice Date was <= X AND where the Assigned, Complete, In Office, In Accounting are all greater than X.
I've used a Sum(if(frequency(if statement to get me REALLY close but I feel like I need to have an AND statement within the second IF like this =SUM(IF(FREQUENCY(IF(AND
Here's what I have that won't work:
=SUM(IF(FREQUENCY(IF(AND(Table1[Assigned]<=A279,Table1[[Complete]:[In Accounting]]<=A279),ROW(Table1[[Complete]:[In Accounting]])),ROW(Table1[[Complete]:[In Accounting]]))>0,1))
If I take the "AND" portion out, this works fine except I need it to ONLY count rows where the given status actually has a date so if an "Assigned" date is empty, I don't want that row to be counted for the Assigned column.
Here's an example of what I'd expect to see in the results. I've listed the count in the each column as well as the corresponding product numbers in parenthesis. The corresponding product numbers are for reference only and won't actually be in the result table.
Date | Notice | Assigned | Complete
5/6 | 2 (1,3) | 2 (2,4) | 0
5/7 | 2 (3,5) | 2 (1,2) | 1 (4)
5/8 | 1 (3) | 2 (1,5) | 1 (2)

OK, assuming you have the original data in A1:F6 then with 2nd table headers in B9:D9 and row labels in A10:A12 then you can use this "array formula" in B10
=SUM((B$2:B$6<=$A10)*(MMULT((C$2:$F$6>$A10)+(C$2:$F$6=""),TRANSPOSE(COLUMN(C$2:$F$6)^0))=COLUMNS(C$2:$F$6)))
confirmed with CTRL+SHIFT+ENTER and copied down and across (see screenshot below)
As you can see the results are as per your requirement. If you replace dates with blanks it will still work
MMULTis a way to get a single value from each row even when you are looking at multiple columns.
I used cell references because I think that's easier, especially when copying the formula across and having a reducing range.......but you can use structured references if you want

Have you tried using COUNTIFS to count based on multiple criteria. It is fairly well documented here: http://office.microsoft.com/en-us/excel-help/countifs-function-HA010047494.aspx (2007+ only)
Basically, you use it like
=COUNTIFS(first_range_to_check, value_you_want_in_first_range, ...)
where the ... represents as many pairs as you want (up to 127 total pairs), note the conditions are AND connection so if you have two pairs, the first pair AND the second pair must return true for that row to count.

Related

How to extract multiple rows that meet a criteria which is given by 2 drop-down lists in EXCEL

I have a sheet that looks like this:
A | B | C | D | E | F
1 NAME | TASK | ADRESS | ORDER_GIVER | COUNT | NOTE
2 DROPDOWN_2 | move | NY, xy_street | Ann | 1 | ...
3 DROPDOWN_2 | fill | CA, yx_street | Rose | 3 | ...
...
100 NAME | TASK | ADRESS | ORDER_GIVER | COUNT | NOTE
101 DROPDOWN_1
102
103 NAME | TASK | ADRESS | ORDER_GIVER | COUNT | NOTE
104 DROPDOWN_1
INITIALLY:
In rows 1-99 you find the tasks with 1 column empty (NAME).
In rows 100+ you find "Tickets" which can be printed (2 rows for example 100-101)
THEN
1, The ORGANISER (me) makes tickets with names, by ctrl+c/ctrl+v the "ticket structure" and by choosing a name from the DROPDOWN_1 list.
2, Then starts to assign the tasks (row 1-99) to people by choosing them from the DROPDOWN_2 list. (note that dropdown name lists contain the same names.)
After this I would like to have the Excel to fill in the tickets by the rows that contain the same name as the ticket. One person can be assigned to more tasks, but one task can only be assigned to one man. (So tickets can have 1 NAME but more rows depending on the 1-99 list.
I am asking you to help me make a formula or function for this "autofill" of tickets because I have been searching for days for a solution however couldn't find a proper one.
In the Similar problems and solutions section you can find 2 links which had the closest answer. Unfortunately neither of them contain dropdown lists. I tried to solve the problem with INDEX(MATCH()) functions, but the problem is that it cannot handle the changes of names.
Thanks you,
Max
Similar problems and solutions:
https://www.get-digital-help.com/2009/09/28/extract-all-rows-from-a-range-that-meet-criteria-in-one-column-in-excel/
Extracting all rows based on a value of cell without VBA
Select A101:F392 and enter this as an array formula (ctrl+shift+enter):
=IFERROR(INDEX(A1:F99,ROUND(MOD(SMALL(IFERROR(CHOOSE({1,2},SMALL(IFERROR(1/(1/MMULT(IF(SMALL(COUNTIF(A2:A99,"<="&A2:A99),ROW(INDIRECT("2:98")))=SMALL(COUNTIF(A2:A99,"<="&A2:A99),ROW(INDIRECT("1:97"))),0,ROW(A2:A98)),{1,1}))+{0.001,-0.001},FALSE),ROW(INDIRECT("1:196"))),COUNTIF(A2:A99,"<="&A2:A99)+ROW(A2:A99)/1000),FALSE),ROW(INDIRECT("1:292"))),1)*1000,0),{1,2,3,4,5,6}),"")

How to verify an unbalanced table in Gherkin?

I have some tests that verify table results, but on some tests my table structures are slightly different in that the column headers and rows are sometimes 'unbalanced', meaning I have 5 column headers on row 1 but the subsequent rows have 6 columns. An example is like this:
| | | | | |
| | | | | | |
The header row's first column aligns with the second row's first two columns, structurally, but cucumber sees this as an unbalanced table, expecting less columns on the second row in order to match the header row. Is there a way to tell Cucumber/Gherkin to ignore these kinds of differences?
I don't there is a way to ignore your unbalance.
I would use two different scenarios.

Structured Reference in an Index/Match Calculated Column Formula for Header Cell Range in a Table

I have this formula in a calculated column that is working great:
=IFERROR(INDEX(Allocation_of_Funds[[#Headers],[End.Nursing]:[Unassigned14]],MATCH(TRUE,INDEX(Allocation_of_Funds[#[End.Nursing]:[Unassigned14]]>0,0),0)),"")
But this formula is giving me trouble and represents what I want in the next calculated column, (based on the value in the previous column above) but it returns a #REF! error:
=INDEX(INDIRECT("Allocation_of_Funds[[#Headers]"&"["&[#[SOURCE 1]]&"]"):[#Unassigned14],MATCH(TRUE,INDIRECT("Allocation_of_Funds[[#Headers]"&"["&[#[SOURCE 1]]&"]"):[#Unassigned14]>0,0),0)
The details of the tables setup is as follows, in case it's helpful:
I have a table with a range of columns and each column represents a different type of account. For each row, any combination of these columns could contain values or blanks, so I've got another set of columns that I want to identify the table column headers for the non-blank columns for each record.
SOURCE1 | SOURCE2 | SOURCE3 | ACCT1 | ACCT2 | ACCT3 | ACCT4 | ACCT5
ACCT1 | ACCT2 | ACCT4 | 500 | 300 | | 100 |
ACCT2 | ACCT3 | | | 200 | 100 | |
ACCT3 | | | | | 500 | |
| | | | | | |
ACCT3 | ACCT4 | ACCT5 | | | 200 | 300 | 50
ACCT1 | ACCT3 | ACCT4 | 123 | | 332 | 100 |
So I need the SOURCE2 column to use the value in the SOURCE1 column to identify the start of the range where I am looking for the next cell with a value, whereby the column header above that value will be returned for the SOURCE2 row value. The same formula will apply to the SOURCE3 column, using the value of the SOURCE2 column to identify the start of the next range.
Thank in advance for picking your brain!
-Lindsay
I used the following formula to pull the headers and place them under the source numbers:
=IFERROR(INDEX($D$1:$H$1,AGGREGATE(15,6,COLUMN($D2:$H2)/ISNUMBER($D2:$H2)-COLUMN($D$1)+1,RIGHT(A$1,1)*1)),"")
I assumed your table's top left corner was in A1 with 1 being the header row and A-C being your source columns and D to H being account columns. The above formula can be placed in cell A2 and copied to the right and down as need be.
You seem to have a grasp of the IFERROR and INDEX function so I will explain the AGGREGATE function:
=AGGREGATE(15,6,COLUMN($D2:$H2)/ISNUMBER($D2:$H2)-COLUMN($D$1)+1,RIGHT(A$1,1)*1)
The AGGREGATE function is a mixture of a bunch of different functions rolled into with the ability to ignore some calculations. Another added feature is that some of the built in functions perform array calculations without the need for arrays.
In this particular case I chose aggregate function 15 which is the same as the SMALL function. I have also told aggregate to ignore calculations which generate errors by using the "6". For the array calculation I have asked it to divide the column number it is working with by the True or False result of that column being a number:
COLUMN($D2:$H2)/ISNUMBER($D2:$H2)-COLUMN($D$1)+1
True in excel math is the same as 1 and False is the same as 0. Anytime the cell is not a number it will try to divide by zero, generate an error, and be ignored by Aggregate function. This basically generates a list of column numbers that meet the criteria of having a number in their column. The subtraction of the D1 followed by a +1 is to convert the column number that is determined, to a relative column under your accounts headers.
The next part of the aggregate function is telling the SMALL operation which number in sorted order needs to be returned. I used the last character in your source header to determine which column number to return. For SOURCE1 the last character is 1 so I want the smallest column number returned. For SOURCE2, the second smallest number is returned. The *1 at the end converts the character to a number instead of 1 as text.
RIGHT(A$1,1)*1
Ergo, if you want to use up to 9 sources you can. You can do more sources as well but you would need to revise this formula or come up with a different way of providing which number of the small list you want returned. And you can expand the D2:H2 reference to be all your accounts, and adjust the D1:H1 reference to cover all your account headers.
Proof of Concept

EXCEL find the last relative maximum in a array (formula, not VBA)

I have a range containing values such as:
169.7978
168.633
168.5479
168.7819
167.7407
165.4146
165.1232
I don't need the maximum value of the range, i.e., the first cell in this example), but the last relative maximum, which in this case is the fourth cell. Is there a way to get this value without having to write a VBA macro? The formula must be general enough to work with a multiple number of maxima.
It may be a bit limited, but you may start somewhere as below.
Stated array in the OP is:
+----------+---+
| y | x |
+----------+---+
| 169.7978 | 1 |
| 168.633 | 2 |
| 168.5479 | 3 |
| 168.7819 | 4 |
| 167.7407 | 5 |
| 165.4146 | 6 |
| 165.1232 | 7 |
+----------+---+
Given this, you can find direct adjacency relative min/max with the following helper columns
Assign a Global_Rank helper column and look for y distro identical trend on both adjacent f(x) with the following formulas ( assuming your data is sorted by the x index )( formulas from Row 2 and filled down ).
RelativeMax:
=IF(AND(D2<=D1,D2<=D3),"RelativeMax","")
RelativeMin:
=IF(AND(D2>=D1,D2>=D3),"RelativeMin","")
Modify as needed. Hope this helps.
Edit:
Although...
If you're going to assume the data is ordered properly, you could also just use =IF(AND(B2>=B1,B2>=B3),"RelativeMin",IF(AND(B2<=B1,B2<=B3),"RelativeMax","")) and skip all the malarkey. This should work with multiple maxima/minima. Please report back with results from your dataset!

Counting the number of older siblings in an Excel spreadsheet

I have a longitudinal spreadsheet of adolescent growth.
ID | CollectionDate | DOB | MOTHER ID | Sex
1 | 1Aug03 | 3Apr90 | 12 | 1
1 | 4Sept04 | 3Apr90 | 12 | 1
1 | 1Sept05 | 3Apr90 | 12 | 1
2 | 1Aug03 | 21Dec91 | 12 | 0
2 | 4Sept04 | 21Dec91 | 12 | 0
2 | 1Sept05 | 21Dec91 | 12 | 0
3 | 1Aug03 | 30Jan89 | 23 | 0
3 | 4Sept04 | 30Jan89 | 23 | 0
This is a sample of how my data is formatted and some of the variables that I have. As you can see, since it is longitudinal, each individual has multiple measurements. In the actual database there are over 10 measurements per individual and over 250 individuals.
What I am wanting to do is input a value signifying the number of older brothers and older sisters each individual has. That is why I have included the Mother ID (because it represents genetic relatedness) and sex. These new variable columns would just say how many older siblings of each sex each individual has. Is there a formula that I could use to do this quickly?
=COUNTIFS($B:$B,"<>"&$B2,$H:$H,$H2,$AI:$AI,$AI2,$J:$J,"<"&$J2)
Create a column named Distinct with this formula
=1/COUNTIF([ID],[#ID])
Then you can find all the older 0-sexed siblings like this
=SUMPRODUCT(([DOB]>[#DOB])*([MOTHERID]=[#MOTHERID])*([Sex]=0)*([Distinct]))
Note that I made the data a Table and used table notation. If you're not familiar [COLUMNNAME] refers to the whole column and [#COLUMNNAME] refers to the value in that column on the current row. It's similar to saying $A:$A and A2 if you're dealing with column A.
The first formula gives you a value to count that will always result in 1 for a particular ID. So ID=1 has three lines and Distinct will result in .33333 for each line. When you add up the three lines you get 1. This is similar to a SELECT DISTINCT in Sql parlance.
The SUMPRODUCT formula sums [Distinct] for every row where the DOB is greater than the current DOB, the Mother is the same as the current Mother, and the Sex is zero.
I have a possible solution. It involves adding two columns -- One for "# older siblings" and one for "unique?". So here are all the headings I have currently:
A -- ID
B -- CollectionDate
C -- DOB
D -- MOTHER ID
E -- Sex
F -- # older siblings
G -- unique?
In G2, I added the following formula:
=IF(A2=A1,0,1)
And dragged down. As long as the data is sorted by ID, this will only display "1" once for each unique person.
In F2, I added the following formula:
=COUNTIFS(G:G,"=1",D:D,"="&D2,C:C,"<"&C2)
And dragged down. It seemed to work correctly for the sample data you provided.
The stipulations are:
You would need the two columns.
The data would need to be sorted by ID
I hope this helps.
You need a formula like this (for example, for row 2):
=COUNTIFS($A:$A,"<>"&$A2,$E:$E,$E2,$D:$D,$D2,$C:$C,"<"&$C2)
Assuming E:E is column for sex, D:D is column for mother ID and C:C is column for DOB.
Write this formula in H2 cell for example and drag it down.

Resources