How to choose random from one column and an adjacent column - google-sheets

For example I have this list of a product and a price:
Product
Price
potato masher
€ 27
dish brush
€ 20
rolling pin
€ 17
doormat
€ 20
mop
€ 22
To choose a random product, I use =INDEX($A$1:$A$5,RANDBETWEEN(1,COUNTA($A$1:$A$5)),1)
Is there a formula or way to randomly choose from two adjacent columns and put it in two other columns? So when it randomly chooses the potato masher, it chooses € 27 for the adjacent row and not for example another random price from that column (Which happens when I use the =INDEX with B instead of A).

Assuming you don't have Microsoft365:
Select two cells, e.g: D1:E1.
Use formula =INDEX(A2:B6,RANDBETWEEN(1,5),0).
Confirm through: CtrlShiftEnter.
If you do have MS365, you don't need to CSE-confirm this.

use:
=INDEX(A1:B6, RANDBETWEEN(1, COUNTA(A1:A6)))

Related

Display of the top 3 customers by number of orders

I am trying to find out the top 3 customers from a list.
I want to do this based on the number of orders.
At the end I would like to be able to display the following values:
Client
Amount of Orders
Summed Amount of Ordervalue
A
4
1.400€
D
3
1.200€
C
2
400 €
My output table is like the following just with way more clients
Client
Order type
Amount per Order
A
Container
300 €
A
Container
300 €
C
Trucking
200 €
B
Storage
100 €
A
Trucking
400 €
A
Trucking
400 €
D
Container
600 €
C
Trucking
200 €
D
Container
300 €
D
Container
300 €
You may use below formula.
=QUERY(A1:C,"select A, count(A), sum(C)
where A is not null
group by A
order by count(A) DESC
limit 3")
Try following query
Select Client,Count(Client) 'Amount of Orders',Sum(Amount) 'Summed Amount of
Ordervalue' From OrderDetails Group By Client
try following
Select Client,Count(Client) 'Amount of Orders',Sum(Amount) 'Summed Amount of
Ordervalue' From OrderDetails Group By Client

Comparing 2 columns for certain words

=COUNTIF(B4:B, "" & D4:D & "")
So column B4:B will have something like this
Joe Smith, STIM
and column D4:D would have something like this
Joe Smith 10/19/1999 AC
I am trying to make a True False statment in Col G that if column B has Joe Smith and Column D has Joe smith it will say yes or no. This will be a list of names that always change dynamically so one day B4 might be Joe Smith but the next day it could be Jan Doe. Column D will be a list of names in alpha order that changes all the time as well.
I was able to replicate what you need with the example provided by using:
=ArrayFormula(IF(D:D="",,REGEXMATCH(LOWER(D:D),FILTER(LOWER(I:I),I:I<>"")&"\b")))
You can see the results in my testing spreadsheet here.
At the moment I have limited the range from column I but you can just change it so it takes the whole column.
Just one little detail is that with this function you can only have 1 name in each row in the list of names.

Conditional Formatting Using Variable Data

I'm building a spreadsheet to use at the family health unit where I work. I have a spreadsheet where column G indicates the patient's gender, and column O indicates the patient's waist circumference value. I would like the cells in column O to turn red if the value were > 80 for women and > 102 for men, according to the data in column G.
try:
=((G2="male")*(O2>102))+((G2="female")*(O2>80))

Add currency symbol's as prefix or suffix in IF statement

I've tried but I can't figure out how to add a prefix of currency symbol when certain conditions are done. For example:
I want that if I choose "$" and "Paycheck", the result in E2 were $10, and if I choose € in A2, the result were 11€.
I've been trying to achieve that but my code skills are improving very slowly..
Can anyone explain me the trick?
Assuming that in case you have € and Paycheck you want to add Price and Tax and this is how 11 is calculated.
Try this in cell E2:
=if(AND(B2="Paycheck",A2<>""),if(A2="$",C2,C2+D2),"")

Arranging the ingredient-quantity data in a single row, to be retrieved elsewhere

I want to implement a table on Google Sheets that contains rows with different data, two of these fields to be related arrays and I'd like to know best way to implement it. There are three different sheets, named Recipies, Ingredients and Dishes. Recipies contain the name of the dish and the list of ingredients, Ingredients contains the nutritional info of each ingredient, and Dishes contains the actual nutritional info of each serving.
Recipies Sheet I want to keep it as readable and visual as possible:
Name Time Ingredients
Pasta 20min {150 spaghetti, 30 sauce, 5 marjoram, 20 cheese}
Dishes:
Name Prot. Carb. Fat KCal
Pasta x x x x
I want to get the recipies' ingredients and quantities data, lookup for its nutritional content and sum the quantities on the Dishes sheet. The Ingredients sheet looks like:
Ingredient Prot. Carb. Fat KCal
Pasta x x x x
Marjoram x x x x
I know how to get row data from a different sheet if ingredients and quantities are arrenged in two rows and each one in different columns, like to sum the total protein in the dish:
=ArrayFormula(SUM(LOOKUP(F5:K5;Ingredients!$B$4:$B$1000;Ingredients!$D$4:$D$1000)*((F6:K6)/100)))/E5
The problem I have is I want to have in a single row the list of ingredients and the quantity used like {150 spaghetti, 30 sauce, 5 marjoram, 20 cheese}. I want to keep it readable at a glance. I tried to use an array but dont know how to make it work.
How can I best arrange data to be in a single row and be able to use it to lookup data on other sheets?
Ideally, you would enter data for each recipe in structured form, such as an ingredient-quantity table, and then display it in readable form, by building a text string from the data using join or similar. General idea is that structured data should be the source of information, while the things displayed for human consumption are derived from that.
But if you insist on using strings such as "150 spaghetti, 30 sauce, 5 marjoram, 20 cheese" as source of information, here is a way to compute nutritional content from them.
Suppose A:B is an ingredient - nutritional content table, such as
Ingredient Protein
spaghetti 2
sauce 4
eggs 10
cheese 6
marjoram 2
and cell E2 has "150 spaghetti, 30 sauce, 5 marjoram, 20 cheese". The following formula computes the amount of protein in this recipe:
=sumproduct(
vlookup(split(regexreplace(E2, "[\d\W]+", " "), " "), A:B, 2, 0),
split(regexreplace(E2, "\D+", " "), " ")
)
Explanation:
the first split-regexreplace combo extracts all words from the recipe, by replacing the digits and punctuation with spaces and then splitting by space. We get the array of four words: spaghetti, sauce, marjoram, cheese
then, vlookup looks up the protein content (column 2 in range A:B). If you also have fat, calories, carbs, etc, then the lookup range will be A:E and the column to use will be one of 2, 3, 4, 5.
the second split-regexreplace extracts the amounts of ingredients, it removes everything that is not a digit from the formula
sumproduct adds the products of these two arrays, computing the total protein content.
All this is fragile because of regex-based parsing of text, and will break if the string deviates from expected format; for example, if a recipe calls for "1 1/2 tablespoons of sugar". In which case, see the first paragraph.

Resources