Spreadsheet Array Formula Tweak - arrays

Trying to tweak this array formula
=INDEX(D26:W26,MATCH(MAX(COUNTIF(D26:W26,D26:W26)), COUNTIF(D26:W26,D26:W26),0)) & " Winner"
It works and returns AAA Winner
It is for a contest - This counts name entries in each cell and returns which person has the most votes in the range.
What I would like it to do is to put the text Winner first then AAA.
Also, this does not handle if there is a tie in which I would like it to say it is a tie and between who so - Tie Between AAA and BBB. Right now, if there is a tie, it simply lists the very first one...
Hope that makes sense.
Thank you in advance.

just switch it to:
="Winner " & INDEX(D26:W26,MATCH(MAX(COUNTIF(D26:W26,D26:W26)), COUNTIF(D26:W26,D26:W26),0))
But for the Tie-Part it gets hard (you would need to check everything against each other... better just make a new small table which holds each participant and then the value (with countif) which then can be sorted...

Related

Extract Data From Table Based on Multiple Criteria within ranges

I have a problem that I would like someone to help me with.
I need to cross data from a table, the table is the following below:
Literally I want to put in the "Yellow" line the amount I want, it can be any one from 0 to 3000. If in "Yellow" put for example 190, which is up to 200, then it will select column F. If you put 1000, then will already select column H.
Then I need to cross data with the lines, which will be up to x m2. That is, if in the line where it says "Green" select for example 0.3. Then it will select line 15. The Result of the 2 questions would be 1000 in this example.
However, I've already made a few attempts, and there I arrived at a formula killer:
=IFS(AND($E$20<=$F$14;$E$21<=$E$15);$F$15;AND($E$20<=$F$14;$E$21<=$E$16);$F$16;AND($E$20<=$F$14;$E$21<=$E$17);$F$17;AND($E$20<=$F$14;$E$21<=$E$18);$F$18;AND($E$20<=$G$14;$E$21<=$E$15);$G$15)
And this formula continues until the end. It's effective, it does its job, but in addition to being huge, it also makes it difficult to edit one day. I would like to try to improve it.
Any idea?
I apologize to everyone who was confused by my earlier attempt to explain my problem. Thank you all.
Per my understanding you are looking for two match criteria. For yellow criteria you look for exact match and for green criteria, the exact match or the next upper value.
You can use INDEX/XMATCH for that as follow using LET function in cell J3:
=LET(rng, B2:G5, upper, 1*TEXTAFTER(TEXTBEFORE(A2:A5, " m2"), " ", -1),
INDEX(rng, XMATCH(J2, upper, 1), XMATCH(J1, B1:G1))
)
or without LET function:
=INDEX(B2:G5, XMATCH(J2, 1*TEXTAFTER(TEXTBEFORE(A2:A5, " m2"), " ", -1), 1),
XMATCH(J1, B1:G1))
Note: The above approach doesn't require a helper column with the upper values, if such information is provided like in the updated version of the question (column E), then use the corresponding range instead.
Here is the output:
It assumes there is a space between m2 and the number in the green column. You need to standardize it in your input. For example the last green row doesn't have a space. If that is not the case you need to cleanup it first, via SUBSTITUTE function for example or manually it seems to be a typo.
The name upper contains the number associated to m2 in the green column using TEXTBEFORE and TEXTAFTER. The first XMATCH uses the third input argument (1) to ensure if the value doesn't exist, then it finds the next upper value. The second XMATCH look for an exact match for the yellow column.
This is a well known use case: Two dimensional lookup or two way lookup. For example you can check: INDEX XMATCH XMATCH to perform 2-dimentional lookup and just to adapt it to your specific case. You can also use XLOOKUP function for similar situations.
I'm trying to do it the way you showed me. However, I don't use excel and therefore I don't have this "LET" formula.
I had to improvise.
Followed this way:
I made a new column with the intended values.
All these values would be approximate, for example, if I put 150 in quantity and say that they are 5m2, it would give me the result of 1400. This is because it is below 200 units and below 5m2. Another example, if you put 499 units and put 13m2, then the result would be 360,
Currently, with this formula, I have already achieved approximations. However, the values are not matching up and when I pass 1500 units then it gives me this error: The value of Parameter 2 of the INDEX function, 5, is out of range.
Have a good year David.

How can I write an array formula that extracts unique values from a list only if they have a certain value in the column next to them?

I have an understanding of how index/match can be used to create a unique list of items. I'm trying to create a unique list of items in a specific category and that is presenting a challenge to me.
For instance, say I have:
INDEX SPY
INDEX SPX
GOLD GLD
GOLD JNUG
GOLD GLD
INDEX SPY
and I want to extract only the unique GOLD values from the list. The output should be: GLD, JNUG.
I wrote a separate array formula to check if the left column is GOLD then output the symbol from the right column but the problem I'm having is that whatever I set for false ends up looking like it's part of the list to the index/match formula.
I was thinking that maybe there's a way to remove all zero-value array elements before exposing it to index/match but I'm out of my league here. Any suggestions on how to get the job done efficiently would be appreciated. Thank you!
Let's assume your data is in A1:B6. With UNIQUE and FILTER this is pretty easy now (Excel 2021+). Use the following in one cell, and it will spill:
=UNIQUE(FILTER($B$1:$B$6,$A$1:$A$6="GOLD"))
In earlier versions, it's a bit more work. You can use the following array formula (Ctrl+Shift+Enter to enter). Here entered into cell D3:
=IFERROR(INDEX($B$1:$B$6,MATCH(0,IF("GOLD"=$A$1:$A$6,COUNTIF($D$2:D2,$B$1:$B$6),""),0)),"")
You drag this formula down until you reach empty cells (the IFERROR() wrapper converts the #N/As that appear after all unique values have been found into ""). The "magic" is here done by IF("GOLD"=$A$1:$A$6,COUNTIF($D$2:D2,$B$1:$B$6), supplying INDEX() with new rows only for those rows that contain "GOLD" in $A$1:$A$6.

Stuck on a Java problem - how do I create an array out of a list and summarize it?

I need to program for school but I'm stuck right now.
Introduction
I have a file named "carlist.txt." This file has on each line information about a car in this order:
vehicle_idnumber num_of_passengers fuel_capacity mpg make
So, a typical line might look like this: 487833 6 20 25 Ford
When you read in the file, you are guaranteed it is “clean”. The data are always:int int int int String over and over. This makes your work a lot simpler.
You also need to add a “method” to your vehicle object definition. This method should be a function that returns a double. The function computes the range of the vehicle. All it does is take the fuelcap and multiply it by the mpg. Your “turn-in” program needs to solve the following tasks.
Program 1:
Write a method which walks the array of cars and prints out the total number of each make of car. Your output should look something like: (these are made up numbers!)
MAKE NUMOFCARS
Ford 17
Subaru 23
GM 8
Porsche 5
Toyota 35
Suburban 12
Program 2:
Write a method which analyzes all the cars and prints out the car id that has the highest range and the car id that has the lowest range. Note: range means fuel_cap * mpg. So, for example you might print out: (note, these are made-up numbers!)
Highest range: 987654 with a range of 430 miles
Lowest range: 234567 with a range of 223 miles
In the example above the big number is the car vehicle number and the “miles” number is the range.
For program 1, I have to create an array (not array list!) but I don't how to deal with the fact that I don't know the size of the array upfront (since I don't know how many carmodels the list contains). How can I add car models or how do I handle the fact that one list might contain 5 car models and the next list contains 15 different models. How do I create this array out of my list?
That is indeed a very weirdly worded question. Given the text you posted, I would assume that "array" here is being used generically to just mean "ordered collection" instead of a literal Java array. If not, you are right that when reading in a file, you have no way to know how long the file is going to be before you finish, so there is no efficient way to make a fixed-length array of the right length to hold an entry for every line.
If you absolutely have to, I can think of 3 ways:
Use an ArrayList when building the collection, then call .toArray() on in when you are done to get it as an array. This is pretty harmless, but also totally pointless unless you need to pass it to a function that happens to only take arrays (which is maybe what is going on).
Make a first pass through the file to find the length, then make an array of that length and do a seccond pass through the file to fill that array. (See here for getting the number of lines in a file).
Make an array that is way bigger than you could possibly need and just keep track of how much you fill it up. Then, when you are walking the array, stop after you get to that number (or when you hit a null).
TBH though if your teacher actually wanted you to do any of those things (especially 2 or 3) they are absolutely insane. I'm guessing this is a misunderstanding somehow.

how to insert a variable for different sentences using vba?

i am trying to make a verbiage generator for my friend.
as i see. i am having difficulties in placing an information in between sentences..
example:
the choice of sentences in dropdown are:
1. i bought (A1) from (A2) last (A3).
2. i got a (A1) from (A2) last (A3).
3. i will give this (A1) to (A2) this coming (A3)
A1 was the cell where you put the name of the item
A2 was the cell where you put the location
A3 was the cell where you put the date
if i enter BAG on A1, MATKET on A2 and FRIDAY on A3,
whichever sentences i choose.. the variables will appear on their respective position in the sentence.
i saw some files with this kind of functions with a separate worksheet for the source.
it goes something like this..
1 i bought Var_item from Var_location last Var_date.
2. i got a Var_item from Var_location last Var_date.
3. i will give this Var_item to Var_location this coming Var_date.
and whenever i choose a sentence, it will automaticaly replace the Var_xxxx to the information i entered.
can someone please teach me how to do this?
thank you very much!

Tallying Unique Names per month using in cell formulas

I have a list of people and dates that they were contacted. From that list, I need to pull the number of contacts per month for unique individuals. Here's an example list:
I need a formula in D:D that returns a 1 for the first instance of a date for each unique individual. I really don't want to manually type all those 1's.
I'll update this with what I come up with - I usually like to show that I've made an attempt, but I'm really not familiar with arrays at all, and I'm sure I'm going to need one here.
I appreciate the assistance, thanks.
Using your provided sample data, in cell C2 and copy down, no array needed:
=IF(COUNTIFS(A$2:A2,A2,B$2:B2,">="&DATE(YEAR(B2),MONTH(B2),1),B$2:B2,"<"&EOMONTH(B2,0)+1)=1,1,"")
Alternate:
=IF(COUNTIFS(A$2:A2,A2,B$2:B2,">="&EOMONTH(B2,-1)+1,B$2:B2,"<"&EOMONTH(B2,0)+1)=1,1,"")

Resources