IF statement being inconsistent - google-sheets

I have a google sheets file that has A Lot of sheets, most of them have data that's pulled from other sheets.
Let's say I have a sheet called Team 1 that has the data for Player 1, Player 2, Player 3 etc.
Now I want to pull the data for each Player into a different sheet, AKA pull his data from Team 1 sheet into a new sheet called Player 1
I used =FILTER normally → =FILTER('Team 1'!A:CC, 'Team 1'!B:B="Player 1")
And this works very well.. BUT I had an ingenious idea to avoid #N/A Error in case of the player not having any data, so I cam up with this:
=IF(
EXACT(
'Team 1'!B:B, "Player 1"),
FILTER(
'Team 1'!A:CC, 'Team 1'!B:B="Player 1"),
"This Player has no data")
Which works well.... sometimes...
I do not understand why this IF statement is inconsistent.
Let's say Player 1 has data in Team 1 and I want to pull it into Player 1 sheet.
If I put the formula in Row 2, it returns False:
But if I put the formula in Row 3 it returns True:
Also another weird thing, it used to work well if I put the formula in row 2 in one of the sheets but not the others.
I do not understand why any of this happened as it makes no sense.. to me at least.
Edit1:
I didn't enclude the Team 1 sheet which was important as my problem wasn't with the IF per se, but my problem was with EXACT.
Apparently EXACT depends on the campared data to be on the same row/cell
If we put the same formula in A1 to A4 in Player 1 Sheet:

To avoid the N/A error in case of an empty output, wrap the FILTER() in an IFERROR() or IFNA()
=IFERROR(FILTER('Team 1'!A:CC, 'Team 1'!B:B="Player 1"), "This Player has no data")
and see if that works?

Related

Query importrange HUGE multiple sheets and turns out error

so I have 5 separate google sheets, each one with the same title and format enter image description here.
There are 8000-10000 rows each so far, as it's a daily sales updating data, yearly may finish with 20000-40000 rows each.
So what I want to do is to merge all of them into another single sheet, and I've tried the following formulas:
enter image description here
Formula A
={IMPORTRANGE(B2,C2);IMPORTRANGE(B3,C3);IMPORTRANGE(B4,C4);IMPORTRANGE(B5,C5);IMPORTRANGE(B6,C6)}
Results:
#VALUE!
"In ARRAY_LITERAL, an Array Literal was missing values for one or more rows."
Formula B (reduced the data to only one month)
=QUERY({IMPORTRANGE(B2,C2);IMPORTRANGE(B3,C3);IMPORTRANGE(B4,C4);IMPORTRANGE(B5,C5);IMPORTRANGE(B6,C6)},"SELECT * Where Col2 > DATE'2022-5-1' AND Col2 <= DATE'2022-5-31' ",0)
Result:
#VALUE!
"In ARRAY_LITERAL, an Array Literal was missing values for one or more rows."
Formula C (check if is the problem of the code)
={IMPORTRANGE(B2,C2);IMPORTRANGE(B3,C3)}
Results:
It works.
So my question is that, there is anyway via google sheet let me merge all the 5 sheets in one (5sheets*40000rows into one sheet) , or it's not the place to manage that volumn of data?
every importrange needs to be run separately before you use it in your joint formula. the array error you are getting is a result of some importranges importing those 7 columns and those importranges that are not connected output one single cell. make sure you allow access to all your importranges.

Google Sheets formula for "if 1: select A, if 2: concat A and B, else leave blank"

This is an updated question to a previous one I had. I realized I had left a very important part out when submitting the last one because I was so hung up on trying to concatenate A and B.
I'm working with a sheet that has a column of names and their rows signal 1, 2, or 0 for 'coming', 'unsure', or 'not coming'. The idea was that by filling in the 0's, 1's and 2's this would translate to a visible table below that printed their names if coming, or printed their names with question marks if unsure and blank if not coming. I had thought to make a column of question marks and if c = 2, concat the name with the mark and print it. Alas, I have had no such luck getting any kind of combination of formulas to work. So I turn to you stack masters. Sheet
try:
=ARRAYFORMULA(IF(C2:E8*1=2, A2:A8&B2:B8, IF(C2:E8*1=1, A2:A8, )))
or more compact:
=ARRAYFORMULA(TRANSPOSE(TRIM(SPLIT(FLATTEN(QUERY(
IF(C2:E8*1=2, A2:A8&B2:B8&"×", IF(C2:E8*1=1, A2:A8&"×", )),,9^9)), "×"))))

Google Sheets VLOOKUP formula stops working when new item values are added to the column being looked up

Hello stack overflowers.
I have recently been creating a nutrition tracker to better track and control my nutrition. However I have run into an issue. So currently I have a 1 sheet in the nutrition tracker which is a "database" of foods and their macro nutrients per gram. In this sheet, I will enter all the foods that I generally eat and their associated per G nutrients.
this food "database" sheet has the following columns.
FOOD NAME, CALORIES, PROTEIN, CARBS, OF WHICH SUGARS, FAT, OF WHICH SATURATED, FIBER, SALT
This database is then used as a reference, so that when I input each meal as I eat it, I can simply select the food from a drop down list and type the number of G in that meal, and the nutrients will all be calculated for me.
I currently have it setup so that I can select food from the drop down list generated by "foods" sheet, within each meal table I have created. This is then correctly filling in the rest of the columns as expected once I input a weight for each meal. There is however a huge problem.
As soon as the FOOD NAME column of the Foods sheet had values in it below row 7 (not sure why this row is the limit) the whole thing stops working, the data grabs based on VLOOKUP just return 0 and do not act as they are meant to. The strange thing is they work absolutely fine until I enter too many foods (7 foods) into the foods sheet.
Please find below a link to my spreadsheet, maybe you can duplicate it and play around a little yourselves to better understand the issue.
https://docs.google.com/spreadsheets/d/1orwih7s_Z4ew8G1vJcR6qlxyMpX8pqK-3Ynj42qQjcQ/edit?usp=sharing
(if you help me fix it, you will have a free nutrition tracking spreadsheet to help you take control of your diet aswell)
Thanks in advance.
In the June tab, clear all formulas in the range D11:K18.
Then enter in D11
=ArrayFormula(IF(LEN(B11:B18), IFERROR(VLOOKUP(B11:B18, FOODS!A:I, {2, 3, 4, 5, 6, 7}, 0)),))
This single formula will process all values entered in B11:B18.
Note the third parameter of VLOOKUP (set to false). If it is ommitted (as in your formula) it will default to 'true'. That means vlookup expects a 'sorted order' which may not be the case for your data.
References
VLOOKUP
try:
=INDEX(IF(B11:B18="";; IFNA(VLOOKUP(B11:B18; FOODS!A:I; COLUMN(B:G); ))))

Excel Count and Multiply cells between sheets

I have 2 sheets, Sheet 1 and Sheet 2.
In Sheet 1 is a list of Vacancies in one cell and next to it is the Name of the person who has those Vacancies.
In Sheet 2 I am trying to find the TOTAL amount of Vacancies that each person listed has using a Formula
=COUNTIF(Sheet1!B:B,A2)
The only problem is that it needs to count in Sheet 1 how many vacancies a specific person has.
eg: it shows John has 3 vacancies when he should have 11.
Added a SUMIF attempt
The issue is that you should use SUMIF() instead of COUNTIF() as per the comments above, though since you are not using Excel but Google Spreadsheets, this opens up other options (note, the two look alike but are actually very different).
You could try utilize QUERY():
Formula in D1:
=QUERY(A1:B,"Select B, Sum(A) where A is not null group by B label Sum(A) 'Total Vacancies'")

Google Sheets INDEX/MATCH with multiple results

test spreadsheet
Tab 'Raw Data' contains a combination of "attendance sheets" from multiple activities. Students are in multiple activities on the same Date.
Tab 'Result' lists all unique Students and Dates.
Goal: 'Result'!B3:D11 marks P or A if that student was P for any of the activities on that Date.
For example: On 12/5, Evan was marked A, A, and P in his activities - so he should be marked P for that Date.
If these were numbers, I think I'd be able to use SMALL or LARGE in combination with INDEX/MATCH to count the results...but I'm unsure how to make this formula work with A's and P's.
Since in your sample sheet you do not use a formula for Unique students I suggest -in cell F3- you use
=UNIQUE(FILTER($A$2:$A$33,B2:B33<>""))
We can now use the above formula as part of the following one in cell G2 so as to get the desired result
=ArrayFormula({B1;IF(COUNTIFS($A$2:$A,"="&UNIQUE(FILTER($A$2:$A,B2:B<>"")),B2:B,"=P")>0,"P","A")})
Drag the above to adjacent cells to the right, to get the rest of the columns.
(Please adjust ranges to your needs)
Functions used:
ArrayFormula
IF
COUNTIFS
UNIQUE
FILTER
try:
=ARRAYFORMULA(QUERY(REGEXREPLACE(SORTN(SORT(UNIQUE(SPLIT(FLATTEN(
IF('Raw Data'!B2:D="",, 'Raw Data'!B1:D1&"♂"&TEXT('Raw Data'!B1:D1, "m/d")&
"♀"&'Raw Data'!B1:D1&"♂"&'Raw Data'!A2:A&"♀"&'Raw Data'!B2:D)), "♀")), 3, 0, 2, 1),
9^9, 2, 2, 1), "(\d+♂)", ),
"select Col2,max(Col3)
where not Col1 matches '#VALUE!'
group by Col2
pivot Col1"))
#Gabe, I've added a sheet ("Erik Help") to your sample spreadsheet. There are three formulas in it.
In A2:
=UNIQUE(FILTER('Raw Data'!A2:A,'Raw Data'!B2:B<>""))
This just generates a list of unique names of students from 'Raw Data'.
In B1:
=FILTER('Raw Data'!B1:1,ISNUMBER('Raw Data'!B1:1))
This generates a list of all dates from the first row of 'Raw Data'.
In B2:
=ArrayFormula(IF(NOT(ISERROR(VLOOKUP(FILTER(FILTER(A2:A&B1:1&"P",A2:A<>""),ISNUMBER(B1:1)),FLATTEN(FILTER(FILTER('Raw Data'!A2:A&'Raw Data'!B1:1&INDIRECT("Raw Data!B2:"&ROWS('Raw Data'!A:A)),'Raw Data'!A2:A<>""),ISNUMBER('Raw Data'!B1:1))),1,FALSE))),"P","A"))
As to how this longer formula works, while I usually leave detailed explanations, I'm honestly just too tired to do the full shebang at the moment. But I'll explain the basics.
You'll notice two occurrences of FILTER(FILTER(...)). The first is just making sure to keep the formula focused only on cells in each sheet that actually have data. This will help speed up processing.
IF(NOT(ISERROR(VLOOKUP(...)))) breaks down to "If you can find THIS... do X."
What we're looking for is every string possible made from every name in the results A2:A concatenated with every data from B1:1 concatenated with "P"; virtually (i.e., in memory), these results will fill the 2D grid in results with such concatenations (e.g., B2 in the grid will store "Jon44170P", C3 will store "Barbara44171P", etc.).
Each of these strings will be VLOOKUP'ed in a FLATTENed virtual column made up of every name in 'Raw Data' concatenated with every data in 'Raw Data' concatenated with the actual 'P' or 'A' in the rest of the 'Raw Data' grid.
If the VLOOKUP is successful (i.e., IF(NOT(ISERROR(VLOOKUP(...))))), then a "P" was found for that name on that date. If it wasn't found, then the default "A" is assigned.
Because these formulas are self-expanding, you can add data to 'Raw Data' as you like without needing to drag formulas anywhere.
I also added conditional formatting to expand or contract the background fill color as data expands or contracts.

Resources