How do I fix this Query in my Google Document? - google-docs

Could not really find much on this issue, and I even had my father, who works with excel all the time, walk away stumped on this one. Hoping you guys could shed some light!
Here is a copy of the document: https://docs.google.com/spreadsheets/d/1dH86E1hZRQMj3UL6n4B81IVEkHS5_djkXhHkOl3LOSE/edit?usp=sharing
So this was made for my Runescape clan for us to determine when users require a promotion; it simply makes things easier for us. I'm pulling the data with IMPORTHTML from a site that already tracks the data, my document just arranges it for our personal use (promotions).
On the right should be a list of just people that need the promotion, however, it seems whoever is first on the column I select with the QUERY (A2:D501, Pea being A2), they get put there regardless if they meet the criteria. In this case, under "General Promotions", they need a Clan XP of 250,000,000 and they must be a Captain rank (it goes Captain -> General), yet the Owner (both under 250m exp and not a Captain), is showing up there and under all categories.
Have no idea why this is happening, so if anyone could enlighten me, I would be greatly appreciative!
All I want is if there are no users who fit the criteria, I can have it say something like "No Promotions Yet". Couldn't figure that one out either.

Does this formula work as you want in cell F3:
=IFERROR(QUERY(A2:D501, "select A,B,D where D >= 250000000 and B contains 'Captain'"),"No Promotions Yet")
You will need to delete the formula you have in columns G & H though - QUERY can output multiple columns rather than needing a separate formula for each one.

Related

Collate all entries from one table that don't exist in another in excel

I have the following formula in the 'Available Staff' sheet:
=LET(AvailabilityCalc,FILTER(AllStaffProjectAllocationTbl, IF(ISBLANK($I$11),1,(AllStaffProjectAllocationTbl[Role]=$I$11))*IF(ISBLANK($I$8),1,(AllStaffProjectAllocationTbl[Employee]=$I$8))*IF(ISBLANK($I$14),1,(AllStaffProjectAllocationTbl[Discipline]=$I$14))* (AllStaffProjectAllocationTbl[End Date]<$I$2)*(TRANSPOSE(MMULT(SEQUENCE(1,ROWS(AllStaffProjectAllocationTbl),1,0),TRANSPOSE(AllStaffProjectAllocationTbl[End Date]>TRANSPOSE(AllStaffProjectAllocationTbl[End Date]))*(AllStaffProjectAllocationTbl[Employee]=TRANSPOSE(AllStaffProjectAllocationTbl[Employee]))*(1)))-MMULT((TRANSPOSE(AllStaffProjectAllocationTbl[Employee])=AllStaffProjectAllocationTbl[Employee])+0,SEQUENCE(ROWS(AllStaffProjectAllocationTbl),1,1,0))+1=0)),IFERROR(SORT(INDEX(AvailabilityCalc,SEQUENCE(ROWS(AvailabilityCalc)),{1,4,5,9}),4),""))
that sits in A2 and pulls in all staff that are available after a specific date defined in I2. This unfortunately has an issue as it pulls the data from the staff that have been allocated to a project previously from a 'Staff Project Allocation' sheet and doesn't incorporate the staff from the 'Staff Details' sheet that are yet to be allocated to a project.
The 'Staff Project Allocation' sheet :
The 'Staff Details' sheet :
Someone kindly helped me with the above function and I'm not sure how to modify it to do what I want. Could it be simpler to keep the above as is and create a new set of data to the right of it say, that pulls in the entries from the 'Staff Details' sheet that don't appear in the data created by the formula and are available from the date specified - whilst also being a development role, which I can do by checking their discipline against another table? Or is there a way to modifiy the formula above to incoporate the data? Something I also need to incorporate in the above function, which I overlooked originally, is to exclude any staff member that has had their employment terminated as noted in the Employment Status columns, so any suggestions on how to incoporate this too would be greatly appreciated.
I'm also starting to wonder whether a VBA solution maywell be a better approach, thoughts?
Edit 1
Adjusted function based on the suggestions from Max below. This now includes the ability to filter based on the employment status.
=LET(
staff, AllStaffProjectAllocationTbl,
employee, AllStaffProjectAllocationTbl[Employee],
role, AllStaffProjectAllocationTbl[Role],
discipline, AllStaffProjectAllocationTbl[Discipline],
endDate, AllStaffProjectAllocationTbl[End Date],
employmentStatus, AllStaffProjectAllocationTbl[Employment Status],
rowCt, ROWS(AllStaffProjectAllocationTbl),
roleSelection, $I$11,
employeeSelection, $I$8,
disciplineSelection, $I$14,
availableFromDate, $I$2,
empStatusSelection,"Employment Terminated",
mmult_1, MMULT(SEQUENCE(1,rowCt,1,0),TRANSPOSE(endDate>TRANSPOSE(endDate))*(employee=TRANSPOSE(employee))*(1)),
mmult_2, MMULT((TRANSPOSE(employee)= employee)+0,SEQUENCE(rowCt,1,1,0)),
roleCondition, IF(ISBLANK(roleSelection),1,(role=roleSelection)),
employeeCondition, IF(ISBLANK(employeeSelection),1,( employee=employeeSelection)),
disciplineCondition, IF(ISBLANK(disciplineSelection),1,(discipline=disciplineSelection)),
empStatusCondition, NOT(employmentStatus=empStatusSelection),
AvailabilityCalc,FILTER(staff,roleCondition*employeeCondition*disciplineCondition*empStatusCondition*(endDate<availableFromDate)*(TRANSPOSE(mmult_1)-mmult_2+1=0)),
IFERROR(SORT(INDEX(AvailabilityCalc,SEQUENCE(ROWS(AvailabilityCalc)),{1,4,5,10}),4),"")
)
Edit 2
I now have two tables, one from the Staff Details sheet, showing all staff who are development staff and still employed, this can be seen on the left in the following image (note this all staff allocated to a project or not) and defined by =FILTER(FILTER(StaffDetailsTbl,(StaffDetailsTbl[Employment Status]<>"Employment Terminated")*(StaffDetailsTbl[Dev Role]="Yes")),{1,1,1,0,0,0,1,0,0}), and a separate table defined by the Let function above in edit 1, showing all staff allocated to a project that are available based on a specified date, see table on the right.
I'd now like to merge the table on the left into the table on the right whilst also removing any duplicate entries. Would the most logical first step to be to adjust the filter for the left table to exclude entries that are in the right table? Then look to merge the two in to the right table somehow? Or is it possible to take the Filter defining the left most table and work it directly in to the function defining the right table?
Edit 3
The following function now filters out the entries from the StaffDetailsTbl Table that don't exist in the AllStaffProjectAllocationTbl Table:
=FILTER(FILTER(StaffDetailsTbl,(StaffDetailsTbl[Employment Status]<>"Employment Terminated")*(StaffDetailsTbl[Dev Role]="Yes")*(IF(ISERROR(VLOOKUP(StaffDetailsTbl[Employee], AllStaffProjectAllocationTbl, 1, FALSE)),1,0 ))),{1,1,1,0,0,0,1,0,0})
Giving the resulting table on the left for staff not allocated to a project and those allocated to a project and who are available after a specified date on the right:
I now need to figure out how to merge the filter formula from the left table in to the Let function above, or alternatively, build another table from the two that supports all the roleSelection, employeeSelection, disciplineSelection and availableFromDate functionality. Any thoughts on the best way I can do this please?
The formula logic is complex enough that it's unlikely someone here would be able to invest the time required to work through this on their own. It means someone has to "reverse engineer" the meaning of every reference, like "what does $I$11 really represent".
While not technically an answer, I can provide some help on how to simplify the problem, and then document the logic for your future reference. This won't meet the technical definition of a "proper" StackOverflow answer, but it's too much to fit in a comment and still better than leaving you empty-handed.
Use LET to simplify
You already have it, so let's go further with it, so we can simplify the formula as much as possible. Here's one example of using LET to further break down the formula, and using alt-Enter to create non-breaking returns in the excel formula:
=LET(
staff, AllStaffProjectAllocationTbl,
emp, AllStaffProjectAllocationTbl[Employee],
role, AllStaffProjectAllocationTbl[Role],
disc, AllStaffProjectAllocationTbl[Discipline],
endDate, AllStaffProjectAllocationTbl[End Date],
rowCt, ROWS(AllStaffProjectAllocationTbl),
mmult_1, MMULT(SEQUENCE(1,rowCt,1,0),TRANSPOSE(endDate>TRANSPOSE(endDate))*(emp=TRANSPOSE(emp))*(1)),
mmult_2, MMULT((TRANSPOSE(emp)=emp)+0,SEQUENCE(rowCt,1,1,0)),
roleCondition, IF(ISBLANK($I$11),1,(role=$I$11)),
empCondition, IF(ISBLANK($I$8),1,(emp=$I$8)),
discCondition, IF(ISBLANK($I$14),1,(disc=$I$14)),
AvailabilityCalc,FILTER(staff,roleCondition*empCondition*discCondition*(endDate<$I$2)*(TRANSPOSE(mmult_1)-mmult_2+1=0)),
IFERROR(SORT(INDEX(AvailabilityCalc,SEQUENCE(ROWS(AvailabilityCalc)),{1,4,5,9}),4),"")
)
This is still a lot to take in, but it separates the complexity of how we found/calculated the inputs from the actual Filter and Result logic at the end. if it was my sheet I'd go further and break the formulas down even more, like giving $I$8 or "transpose(emp)=emp+0" a name as well. The more granular, the better.
Then Document your LET formula right in excel
On another sheet, create an Excel table that documents the LET parameters:
Name
Equates to
Which means
disc
AllStaffProjectAllocationTbl[Discipline]
Discipline Col of Staff Table
roleCondition
IF(ISBLANK($I$11),1,(role=$I$11))
Role from I11, or 1 if I11 is blank
xyz
$I$11
describe what I11 is
I put "xyz" in row 3, but the point is to give a name to each thing, if you are not using name manager.
Hope this helps, either to add clarity for you, or to get someone else started creating a full answer.

Excel 365: COUNTIFS with range as a criteria to lookup

[as per the comments, I am happy to provide a minimal example of the problem if someone can tell me how to upload excel to stack overflow!]
I had a look at previous answers, but nothing seems to fit. Once answer nearly did, but I can't adapt it. Trying to steer clear of VBA but please tell me if needs must.
Basically, I have a large-ish sheet of incident tickets. Some are logged by company A, and some by company B. Unfortunately, the only way to tell which company has logged which ticket is to search in another table on name. What I am trying to do is count tickets that match certain criteria that were logged by, let's say, company B - I have the list of people at company B in a worksheet in the workbook
Obviously, COUNTIFS seems to be the obvious answer, except I can't seem to get a sensible answer from COUNTIFS. :) So, I can get a perfect number of tickets for this or that criterion, but I am unable to add that the ticket should be from company B only, ie: I need a COUNTIFS('Ticket'!$D:$D,'CoBPeople'!$N:$N) term, and I don't see how that's possible to include. In VB, I would know which thing I am iterating over and check each time (inefficient, I know, but we're talking thousands here, not millions!) and just add them up, but it doesn't seem to be possible to get COUNTIFS to "lookup" each name it finds as it does its thing.
Any ideas? I just feels like there is an obvious answer I am missing...
Thanks in advance!
MrBB.
I was hoping to be able to do tis without modifying the ticket dump, but adding a column that checks which company a person works for does look like that's the easiest solution.

Excel match multiple records from timetable

I just stuck with my school homework, it seems easy, but there is always different errors and mistakes.
Context
All I need is to connect information from 3 pages.
The first one is timetable of trainings.
The second page is "groups"
Players page
Question
1) Here is my first question. How I can put the time from the "timetable" page ?
I tried vlookup with the easiest group "children 5-7" but even this doesnt work.
The problem is that there is many possible times of some groups and I need the answer like "17:00, 18:00 etc" then.
2) The second question is with the page "players".
Firstly I need to match group or coach from page "groups". For children all is simple, but excel dont want to work even with this. But, there is one problem more. In adult group there cant be more than 4 players in one group, that why I have TK1, TK2, TK3 and TK4 - all this are for adult A. and TK11, TK22 etc are for adult B. So when its done we should match court and time from page "groups".
There is my spreadsheet so be free to try it right here. Hope you will help me!
Ref
https://docs.google.com/spreadsheets/d/1PNp60xmHOx_Q1wBc33WrzIaWmeNG5UMhi-4roV7dJXU/edit#gid=1868650910
I try to give you some ideas about how to solve your issues
Question 1:
The issue you have with VLOOKUP is that you cannot search on the left of your lookup value in the reference table. As suggested above by BruceWayne, you may use INDEX/MATCH. Considering the structure of your data a good formula could be:
=INDEX('timetable try here'!B:G,MATCH(A2,CHOOSE(B2,'timetable try here'!C:C,'timetable try here'!D:D,'timetable try here'!E:E,'timetable try here'!F:F,'timetable try here'!G:G),0),1)
In fact I am using CHOOSE() to select the column where your case should match, because your courts are numbers from 1 to 5. You may replace this formula in the column D under the label Time in your sheet named "groups try here". By the way the result that you get is only the first occurrence (in case you see a zero with some decimals figures, remind to change format to hours), so you will not be able to get the list as you like. As far as I know Excel does not have such kind of formulas. What you could do is create a VBA formula by yourself. You can find more details in this other post always here in StackOverflow, where I replied to a similar question with some code. I believe that your case is exactly the same.
Question 2
In this part I just added the last argument to the VLOOKUP and your formula works. So the correct formula should be in cell E2 of "players try here":
=VLOOKUP(D2,'groups dont try here'!A2:C15,3,0)
and in cell F2 (Court) of the same sheet:
=VLOOKUP(D2,'groups dont try here'!A2:C15,2,0)
I believe you need also a formula to pick-up the time in cell G2 (time):
=VLOOKUP(D2,'groups dont try here'!A2:D15,4,0)
These formulas of course works with suitable groups starting with "children". For the others it is not very clear to me what you need. If you have grouped all TK in Adult A and Adult B you need to have some criteria to fill in the other cells from your sheet 'groups dont try here'. Also remind that if you recode the TK1 and TK2 (for instance by adding a new column to be used as key for the VLOOKUP), with VLOOKUP you will always pick up only the first occurrence in the table.
If you need more support, please leave a comment.

Can excel clean up free-text user entry?

any help would be massively appreciated - I'm really stuck on this.
I have a field on a user entered form that asks people what university they've attended which, due to technical limitations on our system, has to be free text.
This invariably leads to hundreds of different entries for each university, which means I have to use filter on excel and comb through thousands of entries and manually unify - lack of knowledge on how to automate this limits it's practical use massively.
Does anyone know a way we can automate this process of categorizing (and then unifying) different entries which refer to the same thing (e.g someone might put UCL, another might put "university of college, London" and another "university of college london" - I need to teach the system that all 3 are the same and then convert it on excel).
I have a list of the exact entries we want for each university, and I'm happy to manually 'teach' excel when a user entry matches one of these, providing it then learns this for the future (so as time goes on, we have to less and less manual unifying).
Happy to clarify anything, and thanks so much for any help.
Rob
Don't become the victim of user mischief.
Assign a unique ID for each valid response and have the users enter the ID.
Yup...
As you said, you need to do some teaching, here's is the teaching table. Basically just fill up as you go along. You might ask what is UOL, sorry i just crack it out, just for illustration.
And then you have the users inputs (column E), plus 5 calculated columns (F:J)
And now the formulae, I'll show those in row 2 only, the rest are just filled down.
F2 = SUBSTITUTE(E:E," ","*")
G2 = VLOOKUP(E:E,A:B,2,0)
H2 = COUNTIF(A:A,F:F)
I2 = VLOOKUP(F:F,A:B,2,0)
J2 = IFERROR(G2,IF(H2=1,I2,IF(H2=0,"Never seen before","Need validation")))
Basically the logic flow is
do the exact match vlookup of user input in teaching table, if found, then thats it and return the unified name. (Column G)
if the above exact match not found, then we'll proceed to use the star like Helper vallue. Count how many times the HELPER value is found in the teaching table. (Column H)
do the exact match vlookup of helper value in teaching table. (Column I, for use with Column H)
If value in column G is not an error, then use it,
else if value in Column H is 1, then VLOOKUP(HELPER) value is good. If its 0, then you haven't teach excel on the name before. If >2, then it means it need your further attention, the VLOOKUP(Helper) value could be wrong as there are more than one matches.
The trick here is the HELPER column. by replacing blank space with stars, the vlookup now become some sort like vlookup of a sequence of keywords. Doesn't matter how the user's input is, as long as some keywords found and the sequence match, the countif and vlookup return the value.
And at the same time, you also submit an IT enhancement request ! :)

Excel - replace a formula cell with its result automatically

I am trying to make a sheet to add to templates that I give to my students for homework assignments; some of them are cheating by sending each other the files and I would like to catch them.
I have made a formula cell that populates with the current OS and directory of the file. What I would like to do is have this become text after evaluation so that if another student opens the file it will not change (but the following cell will, and so on..) Here is the formula:
(Cell A1):
=INFO("osversion")&INFO("directory")
(Cell A2 and beyond):
=IF(A1=(INFO("osversion")&INFO("directory")),"",IF(LEN(A1)<2," ",INFO("osversion")&INFO("directory")))
Do you know if there is any way to have a formula cell be replaced by its value after execution without using VBA? (If I use VBA it asks if you want to enable macros on startup which kind of gives the game away...)
Thank you in advance for your help!
There is a workaround: Use Track Changes. If you are using Excel 2010, for example:
Go to the Review tab and in the Changes group click Share Workbook.
Click the checkbox for Allow changes by more than one user at the same time.
In the Review tab, select Track Changes|Highlight Changes.
You may wish to select All for the When option and Everyone for the Who option.
You can then choose to highlight changes on screen and/or list changes in a new sheet.
If you do that before you make your final changes to the file, you can confirm that nobody has Accepted Changes between the last time you saw the file and the time it is returned to you by checking that your last change is shown correctly.
That will then let you see all the people who have edited the file since you last edited it, and what changes they have made.
(EDIT)
As #Siddharth Rout pointed out in another answer, one can use technological means to make cheating on assignments more difficult but a sufficiently resourceful student can always find a way to circumvent such measures.
This predicament can be resolved by distinguishing two cases:
(a) learning opportunities where students can choose to learn (do the assignment and get feedback on their approach - not a mark) or not choose to learn, and
(b) evaluation processes where one can measure how much they have learned (e.g. by getting the students together under one roof).
In case (a) students are not being evaluated and so have no motivation to "cheat". In case (b), they are being evaluated but have no opportunity to cheat.
Do you know if there is any way to have a formula cell be replaced by its value after execution without using VBA?
The answer to your question is "No, it cannot be done"
Even if you considered VBA as an option, it's futile as this is a classic example of XY Problem.
No matter what you do, you cannot stop your students from cheating. Consider these few scenarios.
Scenario 1
Student A has 1.xlsx. Student B has 2.xlsx. After student A finishes his/her assignment, he/she create a copy of 1.xlsx. Let's call it Copy.xlsx. Now Student A gives Copy.xlsx to Student B. Student B opens Copy.xlsx and copies the answers into 2.xlsx. Once finished, Student B deletes Copy.xlsx and gives you 2.xlsx. So now tell me how will you know Student B cheated?
Scenario 2
Student B calls Student A on mobile. They both have their copies opened. Student A gives all the answers on the phone. How will you know Student B cheated?
Scenario 3
Student A and Student B open files in two laptops next to each other and finish the assignment. How would you know who cheated whose assignment?
Alternative?
Get all the students under one roof and then get them fill it up in front of you. There is no other way you can even guess whether someone cheated unless someone is fool enough to mention other students name in his/her template or copied the answers verbatim.
You could always put some text in a cell location that only you know about and make the text white. You could code your text for each student and lock only the contents of that one cell with a password.
That's what I would do...
You can give each of them a different problem (maybe the same problem with different data). You will detect cheating of any kind by just looking at the results.
Programming or IT is not always the solution, even to programming or IT problems.

Resources