KDB/q orderbook add rows - add

In a table I try to bring together the rows that have the same price by adding the quantities for an order book
all_order_ask:([]ask:();ask_qty:();exchange_name:())
Keep the same ask but when it's the same price add the quantities

To answer your followup question: combining the exchange names would be like this:
select sum ask_qty,raze string exchange_name by ask from all_order_ask
assuming that exchange_name values are symbols...if they're already strings then you only need to raze.
I'll highlight again some caveats from my earlier comment:
this leaves a lot of questions: how do you want the resulting table to be ordered? Assuming your ask prices are floats you will have to manage the fact that there will be float precision issues so two floats that appear to be the "same" may not be the same and so they won't group properly

Related

Return Column Index for Each Matching Value in a Row?

Excel Novice using Excel for Business (Online) here.
I am having a difficult time wrapping my head around a way to write a function that does three things for me.
Check a specific row of data in a large table, preferably matching ID's between the two tables (I've been using XLOOKUP to ensure that results are keyed to a specific ID)
Find and return the Column index for every cell within the row with the string "Yes"
SUM associated points tied to the column indexes.
I am creating a new QA Scoring system, and all of the questions share the potential for "Yes" and "No" but depending on the question the number of points will be different. I have been approaching this with the idea that I could return the column indexes, convert them to the points associated to the column indexes, and then SUM them for a score, but I am open to different ideas.
Click Here for a Demo of what I am trying to do, included is the actual data set I was using.
Possible Points
=SUMIFS($O$2:$AH$2,INDEX(Raw_Data!D:W,MATCH(Scoring!A4,Raw_Data!A:A,0),0),"*")
Points Earned
=SUMIFS($O$2:$AH$2,INDEX(Raw_Data!D:W,MATCH(Scoring!A4,Raw_Data!A:A,0),0),"Yes")
These will work with your present setup, but in the long run it would probably be best to just add Possible Points and Points Earned columns to your Table3, if possible.

Rank equally across multiple columns with different data types using a single formula. Is it possible?

See this data set below. It has 3 columns (PTQ, % Growth, $ Growth) that all need ranked individually then summed up and then ranked again for a total power rank of each region. Is there any way I can do this with a single formula? I do this a lot and it would be nice not to have to rank everything individually each time. Basically I need to end up at the "Power Rank" column.
To clarify, I do not want to rank first on one column then another, they all need to be ranked equally together.
Thought I'd add a solution for non-365 users:
Edit: slight amendment so that the returned ranking mimics that of the RANK function, with thanks to #Scott Craner
=MMULT(N(MMULT(CHOOSE({1,2,3},RANK(A2:A10,A2:A10),RANK(B2:B10,B2:B10),RANK(C2:C10,C2:C10)),{1;1;1})>TRANSPOSE(MMULT(CHOOSE({1,2,3},RANK(A2:A10,A2:A10),RANK(B2:B10,B2:B10),RANK(C2:C10,C2:C10)),{1;1;1}))),ROW(A2:A10)^0)+1
which may require committing with CTRL+SHIFT+ENTER, depending on the version of Excel being used.
The static
{1;1;1}
relates to the fact that 3 columns are being queried, and could of course be replaced with a dynamic alternative.
We can use Office 365 LET and SORT. RANK does not allow the use of arrays, so we need to improvise with MATCH and SORT.
=LET(
ptq,A2:A10,
grwt,B2:B10,
grwthd,C2:C10,
ptqrnk,RANK(ptq,ptq),
gwtprnk,RANK(grwt,grwt),
gwtdrnk,RANK(grwthd,grwthd),
sm,ptqrnk+gwtprnk+gwtdrnk,
MATCH(sm,SORT(sm),0))

Counting unique records with multiple criteria for productivity calculation [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have an excel sheet with productivity for my work force. Along with lots of other information about the job, it contains a job number, date, and completed by fields. Each employee may have 50-60 entries for each day they worked.
What I would like to be able to do:
Count how many days each employee has worked by applying a formula that counts a day as work if the employee has any entry against that date (this tracker if for a full year so I'm looking for a way that avoids typing each day of the year).
For example, I want to be able to say to employee A, "You completed 4,000 jobs over 165 days which puts you productivity rate at..."
I want to count the unique values in the date column if Name = Employee A. My data set is about 20K records covering a full year.
[1
How about something like this:
Where Unique Jobs and Unique Dates are calculated with:
{=SUM(--(FREQUENCY(IF($A$2:$A$13=A2,$B$2:$B$13),IF($A$2:$A$13=A2, $B$2:$B$13))>0))}
and
{=SUM(--(FREQUENCY(IF($A$2:$A$13=A2,$C$2:$C$13),IF($A$2:$A$13=A2, $C$2:$C$13))>0))} respectively. Note the formulas are array formulas which means they need to be entered with CTRL + SHIFT + ENTER.
The IF statement handles the "are you the employee I care about?" aspect and returns an array of jobs or dates. We take advantage of the fact that when we bin with the same array with FREQUENCY, we return a zero for any value it has already seen. The double negation, --, coerces the numbers to booleans to ones-and-zeros.
More explanation is available here.
It's likely possible to do this without the FREQUENCY approach or without array formulas, but depending on the size of the dataset, you might want to consider the performance hit.
UPDATE (per comments):
If you have an additional column, say column D = Job_Type, you can add criteria to the IF condition, like so:
{=SUM(--(FREQUENCY(IF(($A$2:$A$13=A2)*($D$2:$D$13="Job Type X"),$B$2:$B$13),IF(($A$2:$A$13=A2)*($D$2:$D$13="Job Type X"),$B$2:$B$13))>0))}
By utilizing multiplication with an asterisk, *, we are implicitly implying an AND condition in the logic; note, if we wanted OR logic we could use +. Also note the additional parentheses. At the end of the day, this says, first check if this is the Emp that I care about; next, check if this is the Job_Type that I care about; if both of those checkout, return me the column of interest and continue as above.
NOTE: The method just described will make things yield the same results, by employee, for the specified Job Type -- in this example, records with Job_Type == "Job Type X". You could do something like: {=SUM(--(FREQUENCY(IF(($A$2:$A$13=A2)*($D$2:$D$13=D2),$B$2:$B$13),IF(($A$2:$A$13 = A2)*($D$2:$D$13=D2),$B$2:$B$13))>0))} and you would obtain different productivity amounts for each Emp and Job_Type combination.
Alternatively, you could create a new Key column, such as Emp_Job_Type which would concatenate the two columns, something like: =A2&D2.
Finally, if you are only interested in one particular Job_type, you could also consider subsetting or filtering your data beforehand. That is, filter for the records of interest upfront and create a new dataset.

Randomize the order of rows

I am creating an quiz in Excel. The structure is:
Serial No. Question Select the right option Right/Wrong Marks
I have a list of some questions and options for answers are in a dropdown list. I want to randomize the questions with their answer options [means I want to randomize whole row].
Is there any build in Excel function?
You might achieve an adequate result with the addition of a column containing `=RANDBETWEEN(x,y) and sorting entire rows on that column. Here x could be your lowest Serial No. and y the highest. Can be changed with F9.
Not truly random because of inherent (minor) deficiencies is how RANDBETWEEN works and since capable of producing duplicate values will tend to favour the status quo.

Nested list in excel

I'm not even sure how to ask this.
I have a database, where each row is a person. Columns are contact info, phone, etc. One column is 'date visited'. There can be multiple dates visited for each person. I don't want to use a comma or stack them all in one field.
Is there a way to have a 'nested' list (not a drop-down menu - just a list of visited dates for each person), such that one person still only consumes one single row?
Yes,
To accomplish this give each person an ID that is unique and won't change.
Then on a separate sheet, store the ID and date.
main sheet ( ID, Name, Contact Info, phone, ect)
second sheet ( ID, date visited)
In database theory this is called a 'one to many' relationship, and what i'm describing is called 'normalizing your dataset'.
In Excel you can now use formulas to manipulate the data however you need to or can imagine after you split this apart.
As you mentioned in comment, counting all visited dates for a user.
On the main sheet to the right you could use:
=countif(Sheet2!A:A,Sheet1!A1)
This would Count all of the ID's in the second sheet that match the current row's ID on your main sheet.
Notes about using one cell:
Storing all the dates in one cell will eventually max it out, and will make it hard ot view/search as it grows so i highly advise against this approach.
If however you insist on keeping the dates in there, you could count the visits by counting the total number of comma's + 1 liek this =(LEN(G1) - LEN(SUBSTITUTE(G1,",","")))+1 This formula takes the length of all the dates, and the length of dates with commas removed and subtracts them to get a number of occurrences.
Notes about using multiple columns:
This approach has the same idea as the one I suggested, where we are associating a number of dates with the row's identity of a person. However, there are a few key limitations and drawbacks.
The main difference is that when we abstract the dates by transposing them to extend vertically we can manipulate them easier, and make a list of 20 dates for one person much easier to read. By transposing the dates vertically in the second sheet instead of using this approach we also gain the ability to use Excel's built in filter. Just storing large amounts of data is useless by itself. While storing it in a way that you can view and manipulate easy makes everything much more powerful.

Resources