Im working on a google sheet document to randomly pick a protein and a side dish for weeknight meals based on a selection. The idea is you select your meat (chicken, beef, pork, etc) and the max amount of calories for the meal and it will select a protein and side dish randomly from a list. Not sure how to go about writing either the equation or a script to do this though. Heres what im working with so far:
This is the main page where you select what you want
This is the protein sheet that will have all the possible selections, so based on the image above would want to randomly pick a chicken dish with 800 or less calories
And finally this is the side, for this I would want to choose a side that is less than the remaining calories, so if the protein had say 500 calories would want a side with 300 or less:
On the Proteins sheet add E3 =randbetween(1,100) and copy the formula down. On the Side/Vegetables add C3 =randbetween(1,100) and copy down. On the Dinner Generator sheet add this query to A8:
=query(Sheet2!A3:E,"select A,B where D contains '"& A3 &"' and B <= "& B3 &" order by E desc Limit 1")
and this to A9:
=query(Sheet3!A3:C,"Select A,B where B <= ("& B3 &" - "& B8 &") order by C desc Limit 1")
And this to A10:
=B8+B9
I named the sheets Sheet1, Sheet2, and Sheet3. Change the sheet names in the queries as needed. I also used desc in the queries so blanks would be at the bottom allowing the lists to be expanded without having to change the queries. I suggest you change fish entries in column D to Fish instead of Tuna, Salmon, etc. Below is a shared example spreadsheet. Make a copy to test.
https://docs.google.com/spreadsheets/d/17SWtKfzDFDV8OeffR7s5PcmmwRMzu6UKzWK26CX7KDU/edit?usp=sharing
Related
I'm looking for a way to copy and paste data between 2 Google Sheets spreadsheets: in spreadsheet 1 I have a shared planner of 10 people, where each marks in his sheet personal commitments divided between morning and afternoon for each day. There are also two spaces M and P where everyone manually marks commitments with me.
In spreadsheet 2 I have the small jobs assigned to each of them with a summary line that tells me if they are free (they can do up to 3 jobs M and P).
I would like to copy the data in this row in the M and P columns in the sheet of each of them.
If you are looking to copy and paste data, you could use CTRL + C CTRL + V as suggested by #Jeremy Thille.
If you want to reference data from another sheet, you can do it this way : =NameOfYourSheet!A1, or ='Name Of Your Sheet'!A1 if the name contains spaces.
If the data is on a different spreadsheet, you have to use IMPORTRANGE function. Take a look at https://support.google.com/docs/answer/3093340.
Not sure about the javascript tag, google-sheets would have been more appropriate.
I was not able to explain it and so I send you an image of files.
I have to copy the row "Peter" in Sheet 2 and paste in sheet 1 following the date and sharing of M (morning) and P (afternoon). In suggested way it is too long, and so I thought to GS.
In image2 you find the result I would like to have
Meanwhile I find a formula that I put in Peter tab, cell marked M and P (1/10) and works very well
in B4 =transpose(query({Planning!A3:DT3};"Select "&ArrayFormula(join(", ";text(query(transpose({column(Planning!C3:BL3);mod(column(Planning!C3:BL3)-column(Planning!C3);2)});"Select Col1 where Col2=0");"Col0")))))
in C4 =transpose(query({Planning!A3:DT3};"Select "&ArrayFormula(join(", ";text(query(transpose({column(Planning!D3:BL3);mod(column(Planning!D3:BL3)-column(Planning!D3);2)});"Select Col1 where Col2=0");"Col0")))))
I have 25 people tabs with six month planning. At the end ok week I delete the related data.
How can I make automatic the work?
Meanwhile I find a formula that I put in Peter tab, cell marked M and P (1/10) and works very well in B4 =transpose(query({Planning!A3:DT3};"Select "&ArrayFormula(join(", ";text(query(transpose({column(Planning!C3:BL3);mod(column(Planning!C3:BL3)-column(Planning!C3);2)});"Select Col1 where Col2=0");"Col0")))))
in C4 =transpose(query({Planning!A3:DT3};"Select "&ArrayFormula(join(", ";text(query(transpose({column(Planning!D3:BL3);mod(column(Planning!D3:BL3)-column(Planning!D3);2)});"Select Col1 where Col2=0");"Col0")))))
I have 25 people tabs with six month planning. At the end ok week I delete the related data. How can I make automatic the work?
community!
I have a table of 3 columns in Google Sheets: Date, Name, Amount.
I want to process data from it, so for every date in the list, there will be a full list of participants and amounts.
If there is no amount for specific date and person, it will be "0", or just leave it blank.
In addition, would like to count the percent of the sum of the amount for each person till the date in the corresponding row.
And it should be dynamically updated, so if a new row added with new name or date or both, so new participant will be added to every date in the output table and new full list of participants for the new date created.
For better understanding, here is the example of the data and output tables
What I've tried?
In MS access query it could be done not so hard.
Here I tried to create 2 new lists of unique dates and participants and connect them through use of CONCATENATE, ARRAYFORMULA, then SPLIT and some QUERY. All this through use of helping column of text, which should be edited manually for every new row...
The code in helping column:
=concatenate(arrayformula(if(isblank($F$3:$F),,";"&$E3&","&$F$3:$F)))
Then split code:
=query(arrayformula(split(transpose(split(TEXTJOIN(";",true,$G$3:$G),";",true,true)),",",true,true)),"Select Col1,Col2 where Col2 is not null order by Col1 ASC",0)
But here I stuck...
Want to pull the amounts for every corresponding date and participant, but...
FILTER reaches first, not existent in the original table combination, and doesn't proceed.
QUERY doesn't fetch the data fully automatically for all the list in the output table.
VLOOKUP gives only one row or complete mess, when use it recursively, or error...
So, how can I do this (if it's possible at all) in google sheets, and so all the output will be fully automatically updated?
Thank you very much!
Update - based on comments
I could not figure out a way to make this through one formula. If this works, you can have a hidden column (say H here) that totals the amount for the person till that date using the formula =QUERY(FILTER($E$3:$G, $F$3:$F = F3, $E$3:$E <= E3), "select sum(Col3) label sum(Col3) ''", 0) in H3.
Then in I3 you can find the % of total till date using the formula =QUERY(FILTER($E$3:$G, $F$3:$F = F3, $E$3:$E <= E3), "select sum(Col3) label sum(Col3) ''", 0)/SUMIF($E$3:$E, E3, $H$3:$H).
Both of the formulae in H3 and I3 need to be dragged down unlike the one in E3. Perhaps someone will be able to offer a better solution.
Previous answer
You can try something like this:
In E3 you can have the formula =ArrayFormula({(FLATTEN(SPLIT(REPT(FILTER(UNIQUE(A3:A)&"✦", UNIQUE(A3:A)>0), COUNTA(UNIQUE(B3:B))), "✦"))), (TRANSPOSE(SPLIT(REPT(JOIN("", FILTER(UNIQUE(B3:B)&"◼︎", UNIQUE(B3:B)<>"")), (COUNTA(UNIQUE(A3:A)))), "◼︎"))), (IFNA(VLOOKUP({(FLATTEN(SPLIT(REPT(FILTER(UNIQUE(A3:A)&"✦", UNIQUE(A3:A)>0), COUNTA(UNIQUE(B3:B))), "✦")))&(TRANSPOSE(SPLIT(REPT(JOIN("", FILTER(UNIQUE(B3:B)&"◼︎", UNIQUE(B3:B)<>"")), (COUNTA(UNIQUE(A3:A)))), "◼︎")))}, {A3:A&B3:B, C3:C}, 2, 0), 0))}). It is a little long but fills Columns E through G dynamically.
Then in H3 you can have the formula =ArrayFormula(IFERROR(((IFNA(VLOOKUP({(FLATTEN(SPLIT(REPT(FILTER(UNIQUE(A3:A)&"✦", UNIQUE(A3:A)>0), COUNTA(UNIQUE(B3:B))), "✦")))&(TRANSPOSE(SPLIT(REPT(JOIN("", FILTER(UNIQUE(B3:B)&"◼︎", UNIQUE(B3:B)<>"")), 3), "◼︎")))}, {A3:A&B3:B, C3:C}, 2, 0), 0))/(SUMIF((FLATTEN(SPLIT(REPT(FILTER(UNIQUE(A3:A)&"✦", UNIQUE(A3:A)>0), COUNTA(UNIQUE(B3:B))), "✦"))), (FLATTEN(SPLIT(REPT(FILTER(UNIQUE(A3:A)&"✦", UNIQUE(A3:A)>0), COUNTA(UNIQUE(B3:B))), "✦"))), G3:G))), "")). This one is dynamic as well.
I tried with your data and added a row on my own and it works.
I'm looking for a specific Google Sheets formula. I believe it's using COUNTIFS & SUMIF, but I can't work out how to do it, any help would be really appreciated.
So, my "C" column has a number of letter combinations in each cell... These are "FHG" "CS" "MO" and afew others. They are a reference to specific market trading strategies and I'm using this sheet to track every trade I make. So C3 may contain "FHG" C4, "MO" C5, "FHG", C6 "FHG" etc.
In the "I" column, there is a 'profit and loss' column which states how much was generated/lost for that particular row... These are formatted to currency.
At the top of my sheet, I have a summary list of each set of letters and I'm using a COUNTIF statement to work out the total number (instance count) of each particular letter combo and from there, I can work out strike rates, percentages etc.
The thing I can't work out is, 'is there a way to count/sum the relative numbers in the "I" column based on a specific letter combo?' For example, let's say running down today's trades, FHG appears on C3, C6, C8, C12, C16 etc. can I collect and sum the numbers (to create a total) from the corresponding P&L column, I3, I6, I8, I12, I16 etc?
My main aim is to have the following at the top in my "Summary Section":
'Letter Combo/Name Of Trading Technique' - 'Number Of Trades' (Using COUNTIFS down C Column) - 'Total % Win Rate' (Number Of Winners/Number Of Total Trades For Said Strategy - This is done using a separate column of Y or N for winners or losers) - The one that I need help with is - "Total Sum Of Money Generated For Each Particular Letter Combo (Trading Strategy)"...... I've worked out how to do the first 3 columns, but I can't work out how to pick the numbers out from the P&L column (I) based on what kind of trade (letter combo) exists in the corresponding (C) column.
If every trade made the same about of money, this would probably be an easy calculation, but because each return is different, this is proving challenging.
Thanks for any insights :)
try:
=QUERY(A:I; "select C,sum(I) where A is not null group by C label sum(I)''")
or just for SB:
=QUERY(A:I; "select C,sum(I) where C = 'SB' group by C label sum(I)''")
if you want a count too:
=QUERY(A:I; "select C,count(C),sum(I) where A is not null group by C")
I'm currently working on a report and I'm attempting to pull in select values from a row to another spreadsheet. The twist is that I'd like to pull in that information in descending order only if a cell on that row contains a certain value.
For this report, I'm interested in pulling in data from column A, B, C, and E, only if the cell in column D is a "Yes". The data must also be listed in descending order, so essentially having a list of the top 10 people who have had the most change in ranking and are located in the Chicago office.
The formula I'm using pulls in data from that spreadsheet into another sheet for reporting purposes:
=Query('Sales'!A2:E,"Select A,B,C,E where A<>'' Order by D Desc Limit 10")
However, it pulls in the data for all columns on the sheet, regardless of whether they're in the Chicago office or not. Is there a way to single out the top 10 rows that contain the "Yes" in column S and get data for the cells in column A, B, C, E in those rows to pull in descending order into another sheet?
Link to sample sheet: https://docs.google.com/spreadsheets/d/1psaOkE2oFMsKlXSawot1zujq5HX9ziowf95cJR_O7rA/edit?usp=sharing
You probably want something like this:
=Query('Sales'!A2:U,"Select A,C,K,T where A<>'' AND S='Yes' Order by U Desc Limit 10")
In Google Sheets for inventory management, sheet1 is stock in which Product and Quantity are mentioned, sheet2 is the sale of the day. I want to automatically deduct stock when a product is written over there, if apple is sold, then it should automatically deduct one quantity from sheet1.
The sheet is here.
Some code like this:
function onedit(sheet2,A2) {
if the product in Sheet2!A2 is in Sheet1!A2:A,Subtract 1 from Sheet1!B2:B
}
In your cell B2, you can insert this formula:
= 4 - SUM(QUERY(sold!$A$1:B,
"select count(A)
where A = '" & A2 & "'
group by A", false))
Then, you can drag it down to let the formula apply to all your rows.
The formula counts the number of occurrences in the "sold" sheet of the term in the column A of the first sheet. The QUERY function returns a table with one column and two rows (header and data). the SUM is applied to it, and reduces the QUERY result to a single number.
As with all formulas, results are kept up to date by the Google sheet automatically.
Instead of having the initial inventory in the formula itself, I suggest to use a separate column, for example column C. The formula above would then start with C2 instead of 4.