Check for amount of new items between two lists - excel-formula

I have a list of groceries. Between Day 1 and 2, I want to know how many new items I gained or lost between the days.
I want a function that can tell me the amount of Food items gained. In this case it would be 2 (Banana and Chicken). I also need it to tell me how many lost, in this case 1 (Oreo).
Thanks!

Gain:
=SUMPRODUCT(((COUNTIFS(B:B,B2:B15,A:A,A2:A15-1)=0)*(COUNTIFS(A:A,A2:A15-1)>0))/(COUNTIFS(B:B,B2:B15,A:A,A2:A15)))
Loss:
=SUMPRODUCT(((COUNTIFS(B:B,B2:B15,A:A,A2:A15+1)=0)*(COUNTIFS(A:A,A2:A15+1)>0))/(COUNTIFS(B:B,B2:B15,A:A,A2:A15)))

Related

Number of days for delivery and number of orders delivered in two separate columns. Is there a way to get summary statistics about orders?

I've had a bit of trouble explaining this so please bear with me. I'm also very new to using excel so if there's a simple fix, I apologize in advance!
I have two columns, one listing number of days starting from 0 and increasing consecutively. The other column has the number of orders delivered. The two correspond to each other. For example, I've typed out how it would look below. It would mean that there were 100 orders delivered in 1 day, 150 orders delivered in 2 days, 800 orders delivered in 3 days, etc.
Is there a way to get summary statistics (mean, median, mode, upper and lower quartiles) for the number of days it took for the average order to get delivered? The only way I can think of solving this is to manually punch in "1" 100 times, "2" 150 times, etc. into a new column and take median, mean, and upper & lower quartile from that, but that seems extremely inefficient. Would I use a pivot table for this? Thank you in advance!
I tried using the data analysis add-on and doing summary statistics that way, but it didn't work. It just gave me the mean, median, mode, and quartiles of each individual column. It would have given me 3 for median number of days for delivery and 300 for median number of orders.
Method 1
The mean is just
=SUMPRODUCT(A2:A6,B2:B6)/SUM(B2:B6)
Mode is the value with highest frequency
=INDEX(A2:A6,MATCH(MAX(B2:B6),B2:B6,0))
The quartiles and median (or any other quantile by varying the value of p) from first principles following this reference
=LET(p,0.25,
values,A2:A6,
freq,B2:B6,
N,SUM(freq),
h,(N+1)*p,
floorh,FLOOR(h,1),
ceilh,CEILING(h,1),
frac,h-floorh,
cusum,SCAN(0,SEQUENCE(ROWS(values)),LAMBDA(a,c,IF(c=1,0,a+INDEX(freq,c-1)))),
xlower,XLOOKUP(floorh-1,cusum,values,,-1),
xupper,XLOOKUP(ceilh-1,cusum,values,,-1),
xlower+(xupper-xlower)*frac)
Method 2
If you don't like doing it this way, you can always expand the data like this:
=AVERAGE(XLOOKUP(SEQUENCE(SUM(B2:B6),1,0),SCAN(0,SEQUENCE(ROWS(A2:A6)),LAMBDA(a,c,IF(c=1,0,INDEX(B2:B6,c-1)+a))),A2:A6,,-1))
=MODE(XLOOKUP(SEQUENCE(SUM(B2:B6),1,0),SCAN(0,SEQUENCE(ROWS(A2:A6)),LAMBDA(a,c,IF(c=1,0,INDEX(B2:B6,c-1)+a))),A2:A6,,-1))
=QUARTILE.EXC(XLOOKUP(SEQUENCE(SUM(B2:B6),1,0),SCAN(0,SEQUENCE(ROWS(A2:A6)),LAMBDA(a,c,IF(c=1,0,INDEX(B2:B6,c-1)+a))),A2:A6,,-1),1)
=MEDIAN(XLOOKUP(SEQUENCE(SUM(B2:B6),1,0),SCAN(0,SEQUENCE(ROWS(A2:A6)),LAMBDA(a,c,IF(c=1,0,INDEX(B2:B6,c-1)+a))),A2:A6,,-1))
and
=QUARTILE.EXC(XLOOKUP(SEQUENCE(SUM(B2:B6),1,0),SCAN(0,SEQUENCE(ROWS(A2:A6)),LAMBDA(a,c,IF(c=1,0,INDEX(B2:B6,c-1)+a))),A2:A6,,-1),3)

Creating a ramdom baseball batting order in excel

I am trying to build a baseball spreadsheet for my little league team. I have 10 players and 15 games. I am trying to figure out a way to populate the batting order where everyone gets an equal numbers of games batting 1-10 in the order.
Does anyone know of an easy way to do this?
As mentioned in the comments, it's impossible to evenly distribute 10 players in 10 batting order positions over 15 games. It's similar to trying to divide 15 by 10 evenly. So you'll have to get creative on how to handle the five remaining games (fundraiser?)
Random but Fair For Ten Games
In answer to your question of creating a random batting order, you'd probably only want to randomize once, and then offset the order by 1 position each game. This will get you each player in one position in for ten games.
Random Each Game
If you truly wanted random each game, you'd probably have some undesirable distribution with some kids getting to bet first multiple times while others never get a turn (hazards of truly random).
I built out a quick spreadsheet on google sheets here that you can see how such a tool could work. If you download and hit delete in a blank cell it will re-randomize the sheet. It's using the functions index and Rank and Rand.
Good luck.

How to solve such an optimisation task?

I was planning on referring to the solver function for this, but I'm not sure that it is suitable for the problem I have at hands. Let me try to explain as clearly and concisely as possible the situation:
I am going to market to buy (say 100 as in the spreadsheet) fruitbowls.
I have 3 bags that I want to split them into according to a specific breakdown 75% in bag 1, 20% into bag 2, and the remaining 5% into bag 3
The key question I have is to do with the allocation into these 3 bags, which should meet the following 3 conditions:
The average price of the bowls in each bag should be exactly the same. I.e. as in the example spreadsheet the overall price is 104.55 paid. So the average price of the bowls in each of the 3 buckets should be as close to this number, and the same across all 3
The number of bowls in each bucket meets my target split (i.e. 75/20/5 split)
Only whole numbers of bowls exist in each bag, and any 0.5 get rounded up to 1
The final output should tell me how many of each bowl at each price should be included in each bag. (e.g. Bag1: 3 at 105, 1 at 110, and 10 at 109, and so on)
I have included a screenshot below of how the idea above starts.
Any help would be greatly appreciated.
Edit: Gentle bump as I'd still like to solve this task.

Solr rangesearch within strings containing chains of characters

I hope I find some Help. I'm pretty new to solr and had the oportunity to participate to a talk about it.
For the following scenario even the consultant, who held the talk was unsure about, therefore I hope someone had the same problem.
I have a list of objects identified by a specific key. For examplepurpose:
There are 500000 employees identified by id's (1-500000). Everyone of these people has to work for the next 2 years. Every day of these Years is identified by a character (employee will work - "A", employee won't be at work - "B"). So every employee got a String containing up to 730, but not every employee has the full amount of 730 characters (a specific employee joined the company later or something).
Example String for employee 256:
AABBAAABAAAABBAB
=> Employee 256 will work 2 days, 1 day he is not working, then he will work 3 days in a row, 1 day freetime, 4 days work, 2 days not at work, 1 day work, 1 day home and so on.
Example String for employee 542:
ABBAABABAAABAAAABABBAABAAAAABBABBABABBBABAABABBABABABBABAAAA
Example String for employee 2:
AAAABABBABABAAAABABABABABA
For dispositionpurposes I now want to get the employees who are 4 days in a row at work to go to dinner with them or whatever.
I want to receive the following results:
employee 256 4 days free after day 8
employee 542 4 days free after day 12, after day 23, after day 56
employee 2 4 days free after day 0, after day 12
I hope you got my problem. The example is only for a better imagination. Is it possible to implement a solution with solr?
Other solution approaches (also for the day representation) are highly welcome. Right now we are dependent on the daily representation (every day has one character). But if you deliver me a high performance solution even this is discussable. The amount of entries (500000) is realisitic for the project.
I would not model this as employees, but as availability. Perhaps with availability as a nested/child object of an employee. And availability object would then be StartDay,NumberOfDays.
The query then becomes a simpler join with condition on the child being NumberOfDays>=4.

Grab next same value in Excel/Google Sheets for RANK/MATCH formula

I have a list of players in Google Sheets that assigns them a rank based on wins, followed by some more match variables — standard stuff.
I then use the rank to order the players in a league table format.
However, when I have two more players with the same rank, I hit a problem. The easiest way to illustrate it is with a link to the spreadsheet. Left side is the data, right side is the outputted table:
https://docs.google.com/spreadsheets/d/1n05ETFfF01uCwp1Q88Z0Zi8XkH-dNm29Ocb6yVP84rU/edit?usp=sharing
My aim is:
To allow drawing players, and thus output:
1= Player 1
1= Player 2
3 Player 3
4 Player 4
But also to add players with a rank of 0 (already calculated) to the bottom of the list, in no particular order, but below those who have played.
May serve for ColumnM, but seems would require adjustments elsewhere:
=if(countif(I$2:I$8,I2)>1,IF((B2=0), 0, RANK(H2,$H$1:$H$531,0))&"=",IF((B2=0), 0, RANK(H2,$H$1:$H$531,0)))
You could reproduce your table (excluding the ranking) with this in N1:
=QUERY(A:G,"select * order by B desc, G desc",1)
and then in M2:
=ArrayFormula(IF(LEN(N2:N),(COUNTIF(S2:S,">"&S2:S)+1)&IF(COUNTIF(S2:S,S2:S)>1,"=",),))
Any kind of algorithm is going to hate ties. They will produce unpredictable results, logic errors.
So you might set up your ranking system to remove the ties. Possibly use the date they joined the league for tiebreaker, which would allow you to rank the players with no stats as well.
Make the rules known to all players. E.g. 3 points for a win, 1 point for a tie, 0 for a loss, tie goes to the player with highest total points scored. If still tied, it goes to player in the league longer. The likelihood of established players getting to the join-date tiebreaker should be as remote as you can make it, so your first tiebreaker should be one that produces a lot of diverse answers.
Also, I am not sure, but I think the reason your question got downvoted was because a) it's a bit vague, and b) in this day and age, you really don't want to be opening data files from unknown people. A snapshot of data from your spreadsheet might have been a better illustration than a link to it. I know I will not open your sheet...I don't know you.

Resources