Maybe I'm asking a pretty basic question, but I've searched here (and on other sites) for an answer and I couldn't find it.
I'm making a work schedule for my workplace on Google Sheets, analogous to the example posted as an image down here, that includes an automatic time card for every worker (that is, a formula answering the question "which days had [WORKER] worked?").
I managed to make one, with the filter formula
=FILTER(A2:A16;{or(COUNTIF(B2:D2;$L$1);COUNTIF(F2:H2;$L$1));or(COUNTIF(B3:D3;$L$1);COUNTIF(F3:H3;$L$1));or(COUNTIF(B4:D4;$L$1);COUNTIF(F4:H4;$L$1));or(COUNTIF(B5:D5;$L$1);COUNTIF(F5:H5;$L$1));or(COUNTIF(B6:D6;$L$1);COUNTIF(F6:H6;$L$1));or(COUNTIF(B7:D7;$L$1);COUNTIF(F7:H7;$L$1));or(COUNTIF(B8:D8;$L$1);COUNTIF(F8:H8;$L$1));or(COUNTIF(B9:D9;$L$1);COUNTIF(F9:H9;$L$1));or(COUNTIF(B10:D10;$L$1);COUNTIF(F10:H10;$L$1));or(COUNTIF(B11:D11;$L$1);COUNTIF(F11:H11;$L$1));or(COUNTIF(B12:D12;$L$1);COUNTIF(F12:H12;$L$1));or(COUNTIF(B13:D13;$L$1);COUNTIF(F13:H13;$L$1));or(COUNTIF(B14:D14;$L$1);COUNTIF(F14:H14;$L$1));or(COUNTIF(B15:D15;$L$1);COUNTIF(F15:H15;$L$1));or(COUNTIF(B16:D16;$L$1);COUNTIF(F16:H16;$L$1))}=TRUE)
that is the day column A2:A16 filtered with a manual array column that check if every row B:D (representing an AM shift) OR every row F:H (PM shift) contains the worker's name $L$1.
This is not an optimal solution, because I have to write the array manually, in a very time-consuming and not flexible way (to add another column/another worker to the workshifts means that I'll have to correct every single row).
Is there another better way to use FILTER? So far I've been trying to use MATCH or HLOOKUP, but I'm a rookie and not so familiar with excel arrays.
Post this formula in your K2 cell:
=query(
{{A2:A\B2:D};{A2:A\F2:H}};
"select Col1 where Col2 = '"&L1&"' or Col3 = '"&L1&"' or Col4 = '"&L1&"'"
)
It will work dynamically with your workers:
Related
Attached is the link of my question
I would like to transpose the data like that.
My original data could be thousand of lines.
My thought is to make the same number of tables of my column title, then combine the four tables into one. My thought is on the google sheet as well. It might do the work but I would like a nicer solution.
A picture of my question
After having answered this question hundreds of times in the last couple years after the discovery of the FLATTEN() function, i decided to write a custom function for Google AppsScript to do it. While in some sense, a custom function is more opaque than the SPLIT(FLATTEN( formulaic solution you will find all over the forums in the last couple years, it is at least a little easier to understand in it's operation by the user.
In your shared sheet there is a new script file called MKHelp.gs. In it, you will find the code that I wrote to construct the "UNPIVOT()" function.
On a new tab in your sheet, you will find this formula in a tab called MK.Help.
=QUERY(UNPIVOT(A2:B,"V",C2:E,"B",C1:E1,"H"),"where Col3 is not null")
for unpivot to work well it is best surrounded by a query() to weed out unnecessary rows. In your case, it is that the "amount" not be "empty" or "null".
The letters "V","H" or "B" that follow each range describe the "shape" of the input data. Whether it is "vertical", "horizontal" or "Both".
Try
=query(arrayformula(split(flatten({(A3:A4&"♦"&B3:B4&"♦"&C3:E4)}),"♦")),"select * where Col3 is not null")
Explanation
step1: =arrayformula(A3:A4&"♦"&B3:B4&"♦"&C3:E4)
step2: =arrayformula(flatten(A3:A4&"♦"&B3:B4&"♦"&C3:E4)) , flatten will put all data inside one single column flatten()
step3: =query(arrayformula(split(flatten({(A3:A4&"♦"&B3:B4&"♦"&C3:E4)}),"♦")),"select * where Col3 is not null")
I am trying to find a formula that will give me the count of unique dates a persons' name appears in one of two different columns and/or both columns.
I have a set of data where a person's name may show up in a "driver" column or a "helper" column, multiple times over the course of one day. Throughout the day some drivers might also be helpers and some days a driver may come in for duty but only as a helper. Basically all drivers can be helpers, but not all helpers can be drivers.
I've attached a link to a sample sheet for more clarity.
https://docs.google.com/spreadsheets/d/1GqNa1hrViX4B6mkL3wWcqEsy87gmdw77DhkhIaswLyI/edit?usp=sharing
I've created a REPORTS tab with a SORT(UNIQUE(FLATTEN)) Formula to give me a list of the names that appear in the DATA Tab.
I'm looking for a way to count the unique dates a name from the name (Column A of the REPORTS Tab) appears in either of the two columns (Column B and/or C of the DATA Tab) to determine the total number of days worked so I can calculate the total number of days off over the range queried.
I've tried several iterations of countif, countunique, and countuniqueifs but cannot seem to find a way to return the correct values.
Any advice on how to make this work would be appreciated.
I think if you put this formula in cell b7 you'll be set. You can drag it down.
=Counta(Unique(filter(DATA!A:A,(DATA!C:C=A7)+(DATA!B:B=A7))))
Here's a working version of your file.
For anyone interested, Google Sheets' Filter function differs slightly from Excel's Filter function because Sheets attempts to make it easier for users to apply multiple conditions by simply separating each parameter with a comma. Example: =filter(A:A,A:A<>"",B:B<>"bad result") will provide different results between the Sheets and Excel.
Excel Filter requires users to specify multiple conditions within parenthesis and denote each criterion be flagged with an OR condition with a + else an AND condition with a multiplication sign *. While this can appear daunting and bizarre to multiply arrays that have text in it, it allows for more flexibility.
To Google's credit, if one follows the required Excel Syntax (as I did in this answer) then the functions will behave the same.
delete what you got and use:
=QUERY(QUERY(UNIQUE({DATA!A:B; DATA!A:A, DATA!C:C}),
"select Col2,count(Col1),"&D2&"-count(Col2)
where Col2 is not null
group by Col2"),
"offset 1", 0)
I'm wondering how I would go about adding to a cell based on two other cells.
For example, I'm creating a Google Sheets document to track profit & loss on certain things in an online game I play.
I'll try to explain this as best as possible.
If cell B71 is equal to the string in cell B7, increase the value in cell D71 equal to the number in cell D7.
However, the values will need to be compared to various other things depending on the item required.
For example, the string in cell B7 might change depending on what specific type of item is needed for that day as it does change daily.
I have cells near the bottom of the sheet which list the different type of item which will show the total amount of items used in that month.
I've tried to explain this a little better as requested below
I'm trying to make a spreadsheet that keeps track of the quantity of a specific item I use in a game for a daily task. This task can be done daily, and to keep track of profit & loss, I have created a spreadsheet to keep track of this.
So, each day, there are three different types of items (runes) that can be used in the machine to create an item called 'Vis Wax'. As Runes are cheap, creating the vis wax can generate a good profit. (I love working with data, hense the spreadsheet.
The image above shows what a daily section looks like. I input each type of rune (has to be 3), input the quantity used and the amount each rune is worth to create the total cost under Total.
Further down below, this table has been created
This will keep track of each rune and the amount used during that month.
So with that said, I'm looking for a solution so that if Air rune is entered in ANY of them slots with the QUANTITY used, it'll update that table accordinly (as well as the other runes that are used too). I've tried nested IF statements, but don't seem to have any luck. With the amount of checks that seem to be happening, I can't seem to find a working solution. As Air Rune might be in slot 1 one day, then slot 3 the next day. So it seems each cell in the Quantity Table will need to compare EACH cell in the daily section, to each rune type that can be used.
Hopefully that has explained it a little better.
Spreadsheet Link
https://docs.google.com/spreadsheets/d/1sYLpZJ46IpNk52gxMoJOIZsOCWToLkC4FF83RBncCf0/edit?usp=sharing
I would suggest you to use a different structure and take all the data from one day in one column, something like this:
In this way you will be able to extend the days keeping the formulas in a really simple way. Below, I will explain some useful formulas that you can use to lighten your work:
Day: =text(DAY(B2),"dddd")
Rune type: Check Data validation to create a drop-down list of your rune types
For counting how many runes have you used you can use SUMIFS function. It returns the sum of a range depending on multiple criteria. In your case, you need apply it three time per rune, as you can have the same rune in three different places. You see it with the following image:
The formula is: =SUMIFS($B$8:$H$8,$B$7:$H$7,A25) + SUMIFS($B$12:$H$12,$B$11:$H$11,A25) + SUMIFS($B$16:$H$16,$B$15:$H$15,A25). In this way you only need to write it once and you can fill the rest of the runes just dragging the mouse. If you need more days just change the column H with the last column that you want to take.
I assume that with all this information you can also keep track of your monthly statics easily. I suggest you to create a different sheet for each month.
I hope that my answer was useful, let me know if you have any doubt.
George, I agree with #fullfine, your data structure does not seem ideal for data analysis. And it doesn't seem that efficient for data entry either, with the sideways scrolling (at least on my screen).
But I recognise that you might not want to change it, perhaps having specific reasons for that layout, and having invested time in it. So I offer this formula as an alternative, which basically pulls the needed cells from your existing sheet, and comes up with the totals you'll need.
=QUERY(QUERY({B7:D9;G7:I9;L7:N9;Q7:S9;V7:X9;AA7:AC9;AF7:AH9;
B20:D22;G20:I22;L20:N22;Q20:S22;V20:X22;AA20:AC22;AF20:AH22;
B33:D35;G33:I35;L33:N35;Q33:S35;V33:X35;AA33:AC35;AF33:AH35;
B46:D48;G46:I48;L46:N48;Q46:S48;V46:X48;AA46:AC48;AF46:AH48;
B59:D61;G59:I61;L59:N61},
"select Col1, Col2, Col3*Col2 where Col1 <>'' order by Col1 label Col3*Col2 '' ",0),
"select Col1, sum(Col2), sum(Col3) group by Col1 label sum(Col2) '', sum(Col3) '' ",0)
The same formula can be used for each month, since it always totals all 31 days, even if the month has fewer days.
For your Rune table in the Statistics sheet, you only need the firsts two columns, so you could delete the "sum(Col3)" from the last select statement.
For your smaller financial table, you would take the sum of the Col3 produced by the above formula, ie. the total value of all the runes used. A similar formula would be used to collect the count of the wax produced, its value, and the profit/loss for each day. This would let you complete the financial table.
If you do decide to go with this approach, and want any help with completing the tables, or the formulas, please share your sheet so "anyone can edit it", to make it easier for me to assist you.
Below is a sample of the Google Sheet I'm working on:
https://docs.google.com/spreadsheets/d/1LDsfn_FMdUSfuFZAyuXf5gdlOSN9yLqhT1RY8aX7Nfs/edit?usp=sharing
On the spreadsheet Team Totals, I'm trying to calculate all the sales based on the date, the type of sale, and the program type starting from Row 27.
The problem I have run into is that the Named Range, Consultants, only pulls the data from the first cell of the Named range (Octo). What I want is for a formula that will pull the data of the selected range from each entry in the named range and sum them together.
For reference, I put what the proper values should be starting from Row 33.
The closest example I have seen was from this website: https://www.got-it.ai/solutions/excel-chat/excel-tutorial/sumif/sumif-across-multiple-sheets
However, I get the same problem that only the first cell in the named range gets pulled.
I feel like I'm missing something simple, but I have been bouncing it around my head for hours and can't figure it out. Any help is greatly appreciated.
So after trying to figure out a way not to use an iterative process, I folded and did this:
=arrayformula(SUMIFS(INDIRECT("'"&$B$4&"'!F6:F100"),INDIRECT("'"&$B$4&"'!D6:D100"),$B$2,INDIRECT("'"&$B$4&"'!E6:E100"),E$27,INDIRECT("'"&$B$4&"'!A6:A100"),$A41)+
SUMIFS(INDIRECT("'"&$B$5&"'!F6:F100"),INDIRECT("'"&$B$5&"'!D6:D100"),$B$2,INDIRECT("'"&$B$5&"'!E6:E100"),E$27,INDIRECT("'"&$B$5&"'!A6:A100"),$A41)+
SUMIFS(INDIRECT("'"&$B$6&"'!F6:F100"),INDIRECT("'"&$B$6&"'!D6:D100"),$B$2,INDIRECT("'"&$B$6&"'!E6:E100"),E$27,INDIRECT("'"&$B$6&"'!A6:A100"),$A41)+
SUMIFS(INDIRECT("'"&$B$7&"'!F6:F100"),INDIRECT("'"&$B$7&"'!D6:D100"),$B$2,INDIRECT("'"&$B$7&"'!E6:E100"),E$27,INDIRECT("'"&$B$7&"'!A6:A100"),$A41)+
SUMIFS(INDIRECT("'"&$B$8&"'!F6:F100"),INDIRECT("'"&$B$8&"'!D6:D100"),$B$2,INDIRECT("'"&$B$8&"'!E6:E100"),E$27,INDIRECT("'"&$B$8&"'!A6:A100"),$A41)+
SUMIFS(INDIRECT("'"&$B$9&"'!F6:F100"),INDIRECT("'"&$B$9&"'!D6:D100"),$B$2,INDIRECT("'"&$B$9&"'!E6:E100"),E$27,INDIRECT("'"&$B$9&"'!A6:A100"),$A41))
This formula allows me to cut and paste it to various cells easily, and does the job I need it to, while still using the indirect reference so I can change names without breaking the formula (granted I change the worksheet name as well).
I will need to edit this to include all possible worksheet amounts I can forsee, but once it's done, I won't have to tinker with names anymore.
I'm not happy with this answer, as it creates a really long and ugly formula, essentially repeating the same formula 20 times, but it does work. I feel like there should be an easy function that would be able to do this.
This will return Total sales:
=if(isna(ArrayFormula(QUERY({Lo!$A$5:$F; Tulio!$A$5:$F;Ya!$A$5:$F; Miguel!$A$5:$F;Kevin!$A$5:$F; Octo!$A$5:$F}, "select sum(Col6) where Col1=date '"&TEXT(A28,"yyyy-mm-dd")&"' label sum(Col6) ''",0)))=TRUE,0,ArrayFormula(QUERY({Lo!$A$5:$F; Tulio!$A$5:$F;Ya!$A$5:$F; Miguel!$A$5:$F;Kevin!$A$5:$F; Octo!$A$5:$F}, "select sum(Col6) where Col1=date '"&TEXT(A28,"yyyy-mm-dd")&"' label sum(Col6) ''",0)))
BTW, I get Total sales of $0, $615.50 and $2,498.00
The best way to pull data from a lot of unknown tab names without a script is to actually CREATE the tab names beforehand. On your sheet it looks like you're anticipating/making space for 21 employees. If I were you, I would just create 15 more tabs named Temp7,Temp8,Temp9... etc. Then you can just "hide" those tabs. Then a formula can be built in your totals section that will easily stack all the tabs up using an array literal and a QUERY( { } ) to add up the totals for you without all this INDIRECT() nonsense that you have been going through to pull from the individual tab names.
Would pre-adding tab names be something you were interested in if I could show you the formulas to make the totals easy to calculate?
I am looking to find the average of a running list with values broken down by month.
The problem I'm having is excluding the current month from the formula.
I've tried using =indirect and =counta, but only got errors.
The closest I've been able to get is by using the sum and divide method, but it does not produce consistently accurate results.
https://docs.google.com/spreadsheets/d/1YH8vlvGAoZ9Z-uJTdesgmhX8t6pz3JoEhqi4t9-APSE/edit?usp=sharing
Any guidance is appreciated. The sheet is open for comments if it is easier to answer that way.
Its' a little more than what you're specifically asking here, but maybe this gets at what you're really going for. Take a look at a new tab called MK.help where you will find this single formula in cell A1 that populates the whole table.
=ARRAYFORMULA(QUERY({IFERROR(EOMONTH(Expenses!A:A,-1)+1),Expenses!B:C},"select Col1,AVG(Col2) where Col1<"&EOMONTH(TODAY(),-1)&" and Col1 is not null group by Col1 pivot Col3 label Col1'Month-Year'"))