I am trying to populate B2:D5 with "yes"/"No" ( Figure 1) based on the criteria that if I find the respective pvalue( Column A) , in the 'Test' column in a separate sheet and the Fvalue matches the column header of figure 1. I tried using the formula visible in figure 3. However, it incorrectly labels the cow and chicken columns. Which I suspect is due to it stopping at the first " True" value it finds, and not iterating over the other values once it finds said true value.
Use COUNTIFS()
In B2:
=IF(COUNTIFS(Sheet1!A:A,$A2,Shee1!B:B,B$1),"Yes","No")
Then copy over and down the grid.
Where Sheet1 is the list.
Related
I am trying to figure out a formula to find the first non blank cell with data on a separate tab from where I need the value returned. I've tried the following formula but no luck: =INDEX(Sheet2!H:H,MATCH(1,Sheet2!A:A=Sheet1!A3)*Sheet2!H:H<>"",0)
On Sheet 1 under column "Value from Sheet 2" I need the value from Sheet 2 under column H that is not blank using Sheet 1's "Name" column as the reference, in this case value "123" is the first non blank cell for name "ABC" on Sheet 2.
Thank you
In your data above, =sheet2!A$3:A$6=A3 is going to return {true;false;false;true}.
Further, =NOT(ISBLANK(sheet2!H$3:H$6)) is going to return {false;true;true;true}.
Thus, =(sheet2!A$3:A$6=A3) * (NOT(ISBLANK(sheet2!H$3:H$6))) should get you the array {0;0;0;1}, which is what you want to lead you to desired cell.
=MATCH(1, (sheet2!A$3:A$6=A3) * (NOT(ISBLANK(sheet2!H$3:H$6)))) gets you the index to the first hit, which is 4, and using that as in index into H$3:H$6 gets you all the way home.
But I’d exploit the more useful features of XLOOKUP instead and I resort to index/match only when required—which is pretty rare now that XLOOKUP exists:
=XLOOKUP( 1, (sheet2!A$3:A$6=A3) *
(NOT(ISBLANK(sheet2!H$3:H$6)))), sheet2!H$3:H$6)
One fewer functions, AND it adds the ability to handle a not-found condition.
This all should still work if you just decided to use A:A and H:H as in your previous formula.
I'm trying to do something similar in vba which I have an idea of only in python for loops. Can someone teach me how to do this in vba, either in function or module macro please :
For each distinct values in column A4:A30, there should be no more than 9 distinct values in column C4:C30. If true, return 'OK' in cell A1. if false, return 'Error' in cell A1'
e.g As in the picture, Sam should not have more than 9 distinct fruits. Same goes to Mary
Update :
I have tried the filterxml method and unfortunately didn't seem work for me : [1] https://i.stack.imgur.com/cbmTs.png
Solution for excel with filter/unique formulas
Easiest way to achieve it in Excel365 is: add extra column which counts unique values (Fruits) for each Key (Names) and find maximum value in this column
Start with formula that find each non-blank which fits the key.
=FILTER($C$4:$C$30,($A$4:$A$30=A4)*($C$4:$C$30<>""))
Then delete duplicates:
=UNIQUE(FILTER($C$4:$C$30,($A$4:$A$30=A4)*($C$4:$C$30<>"")))
Then check how many cells we have in filtered data without blanks and duplicates:
=COUNTA(UNIQUE(FILTER($C$4:$C$30,($A$4:$A$30=A4)*($C$4:$C$30<>""))))
Then expand our new-column (column B in my case) formula to each row in our Keys.
And finally add formula to A1 which checks maximum counter:
=IF(MAX($B$4:$B$30)<10,"OK","Error - to many velues")
*There is a little typo, it should be "Error - to many values" =)
Below how the worksheet looks in my testfile
Solution for older versions of excel
I've checked if i am able to make it works without these formulas and it is possible:
We need to start with counting if there is for key-value above current row
=COUNTIFS($A$4:A4,A4,$C$4:C4,C4)
In case we have duplicates above, they should be already counted so we skip them:
=IF(COUNTIFS($A$4:A4,A4,$C$4:C4,C4)>1,"",1)
Now we have colum with "1" or blanks. In that case we need to count each non-empty cell above which correct key (name) and add 1 so instead "" and "1" we will have "" or 1, 2, 3, 4, ...
=IF(COUNTIFS($A$4:A4,A4,$C$4:C4,C4)>1,"",COUNTIFS($A$3:A3,A4,$F$3:F3,">0")+1)
Edit
I have added one extra IF to skip keys if value is blank:
=IF(C4="","",IF(COUNTIFS($A$4:A4,A4,$C$4:C4,C4)>1,"",COUNTIFS($A$3:A3,A4,$B$3:B3,">0")+1))
Cells Formula in A1 is the same
=IF(MAX($B$4:$B$30)<10,"OK","Error - to many values")
Quick Note:
Some formulas have range which starts on 3rd row instead of 4th; Its intended because we are counting cells above and at first row of data we need to have choose something above. This code assumes that you don't have numbers (on column B) or names (on column A) in row 3;
Below I am attaching screen with example; This screen have additional columns (D-F) which isn't required, its only do display how final formula was created.
I want to concatenate the value of two columns in the current sheet and then result should be compared with the concatenation of two column value in another sheet.
e.g - The entered value in Column W and X in current sheet after concatenation should be compared with the existing value in column Y and column Z(after concat) of another sheet.
I have tried using the formula COUNTIF(Sheet2!CONCAT($W$2,$X$2:$Y$2,$Z$2),A2)>0 and some different alteration in this but it seems COUNTIF has range and criteria as argument and this is string which is causing error.
If you want to compare, a simple '=' will do.
Concatenation can be done using '&'.
in current sheet:
=W1&X1=Sheet2!Y1&Sheet2!Z1
will return TRUE if both concatenations are equal and FALSE if they are not.
To find the value W1&X1 in the entire range, I suggest you use a help column (unless you are willing to write a macro). In the help column of sheet1, you concatenate the values (=W1&X1 - drag down). In the hlep column of sheet2 you do the same. Then you make an additional column to check for matches, by using
=match(ValueHelpColSheet1,HelpColSheet2,0)
This formula returns the row number in which the match is found and an error when the corresponding value is not found. You can replace this error with something else using IFERROR if you want to.
I am trying to populate B2:D5 with "yes"/"No" ( Figure 1) based on the criteria that if I find the respective pvalue( Column A) , in the 'Test' column in a separate sheet and the Fvalue matches the column header of figure 1. I tried using the formula visible in figure 3. However, it incorrectly labels the cow and chicken columns. Which I suspect is due to it stopping at the first " True" value it finds, and not iterating over the other values once it finds said true value.
Use COUNTIFS()
In B2:
=IF(COUNTIFS(Sheet1!A:A,$A2,Shee1!B:B,B$1),"Yes","No")
Then copy over and down the grid.
Where Sheet1 is the list.
I am trying to lookup a table in one of my sheets. my table consists of three columns and an unlimited amount of rows.
My table can be seen here:
In my second sheet I wish to write a formula which searches all rows in the table and looks for an exact match in column A and column B, this means it must find the row where column a has a value of "jan" and in that same row the second column must have value "y". Should it find this match, it should return the value of column C.
I tried researching hlookup but that is for horizontal tables so i dont believe this would work. I looked into Vlookups also but that only allows one criteria search instead of looking for two matches.
Can anyone shed some light here please?
You can use index and match with multiple criteria
=INDEX($A$1:$C$1000, MATCH("Jan"&"y", $A$1:$A$1000&$B$1:$B$1000, 0),3)
press CTRL + SHIFT + ENTER when entering this formula.
Convert the range to a table (ctrl-t) and then use SUMIFS to search the table based on two criteria
=SUMIFS(Table1[Alteration],Table1[Month],"Jan",Table1[Products],"y")
This is saying "give me [Alteration] where [Month] = "Jan" and [Products] = 'y'...this returns 364.
You can point the criteria at separate cells containing your criteria.
Be aware that if there is more than one row with identical data (ie more than one row with both 'Jan' and 'y'), column C will be summed together.
The INDEX function has the syntax
INDEX(array, row_num_in_array, [column_num_in_array])
And MATCH returns in the index location of a logic match
MATCH(lookup_value, lookup_array, [match_type])
Combining the two is a flexible technique, and surprisingly powerful -- the logic in a match lookup_value can be a complex condition.
SIMPLEST CODE
Operate on the whole column
INDEX(C:C, MATCH("Jan"&"y", A:A&B:B, 0), 1)
nb./ A:A is excel code for "all of column A". You can instead use:
RESTRICTED CODE
Operates on a subset of the sheet.
INDEX($C$2:$C$1000, MATCH("Jan"&"y", $A$2:$A$1000&$B$2:$B$1000, 0), 1)
Note that you MUST use identical row length arrays (eg. rows 2:1000) or the formula will not work. MATCH only knows how many rows into its lookup_array it got, you need to ensure its rows match those in INDEX's array
PS. apologies this is close to the previous answer, but the details were too long for a comment.
PPS. I missed the clarifications to the first answer. That will work, but there is no need to use all three columns as the array in the INDEX function. You are only returning data from column C after all.