Bring back 10 lowest values based on a condition - google-sheets

I have a table measuring the distance and time via public transport between two postcodes. The postcodes are down column A and also are written in row 1:1 (photo below to explain)
I want to write a formula that says
Match Area name - ie 'Holborn' in the horizontal row, search down column matching 'distance' and return 10 smallest values telling me the distance BUT also bring back the matching store (from column A).
Help very much appreciated.enter image description here
I was trying to achieve it with a filter, sort and limit but I'm not getting anywhere.

try:
={A2:A, FILTER(B2:Z, B1:Z1="Holborn")}

Related

Having problems converting formulas to arrays

Here is the sample workbook: https://docs.google.com/spreadsheets/d/1FqkXO8sdpeP9GPerdg8o2zcSiTV7o8gA-07iBvqw4Yw/edit#gid=1252102463
I'm working off the size tab but I have a "workingsize" tab that someone helped me with. The formulas in that sheet are working great.
ColN in Size corresponds to ColR in WorkingSize. In the absence of context, I'm looking for those two outputs to be identical and can't figure out how to get the formulas to behave correctly.
For more context on Size:
Eventually, the data entered into the red section will exist on an entirely different sheet. I'm good at referencing between sheets but just wanted everyone to be aware. This is the data I'm having trouble with.
in K6 & below, you enter in a type of pizza. right now it's free text but ultimately, it will be a drop down from the range A2:A. That range also matches the headers in F3:H3. In theory, as new items are added to the A2 range, new columns will appear here.
ColL is a number - it represents a dough ball weight.
ColM is identifying which column from the table to be searching against.
ColN then takes the weight, rounds it to the nearest value in the corresponding col for type, and then outputs the corresponding size.
ColN in Size is my attempt to take the formulas from colR in workingsize and turn them into an array.
You can try with XLOOKUP. With INDEX and XMATCH you narrow the weightes by the match on the name of the column. Then with MAP you can convert it in an array. Change the last -1 to 1 if you want to round it up instead of down:
=MAP(K6:K,L6:L,LAMBDA(type,wt,IF(wt="","",XLOOKUP(wt,INDEX(E4:H,,XMATCH(type,E3:H3)),D4:D,,-1))))
PS: I deleted the column of key value, since it was not necessary
UPDATE:
To find closest value, you can use this: it sorts D column by the absolute value of the difference between the corresponding column and the weight. SORTN and the first 1 returns only the first value, meaning the closest to the weight
=MAP(K6:K,L6:L,LAMBDA(type,wt,IF(wt="","",SORTN(D4:D,1,,BYROW(INDEX(E4:H,,XMATCH(type,E3:H3)),LAMBDA(d,ABS(wt-d))),1))))
Let me know!

Formula for calculating a cell value based on variable percentage bands with specific threshold levels

I have a Google Sheet with two tabs - one containing percentage "bands" values and the other with data in a table which includes rows for new entries and columns off to the right edge which store running totals depending on the entry type. The running totals depend on the row entry being of the same type and month period. This all works as expected.
I need to calculate a value in column I based on a row entry amount/cell (column H) which references the running total for that entry type AA:AF and month and then uses the relevant predefined percentage "bands" values (tab R1).
I had successfully got this working when a single entry would only ever cross one "band" level (the bands were previously tens of thousands apart) by using SWITCH and VLOOKUP functions.
The current formulas in column I use this method which no longer works since the percentage bands are now much closer together than they were before and a single entry could take the running total value for that entry over multiple bands (and not just the previous band, as before).
On the example sheet, cell H6 contains 9,900 as a test value since this increases the running total for that row AB6 to 16,313 from the prior running total for that type, 6,413 and spans 4 percentage bands:
Band A: 0-7,500 - 5%
Band B: 7,500-10,000 - 7.5%
Band C: 10,000-15,000 - 15%
Band D: 15,000 - 25,0000 - 17.5%
My original formula first checks the entry Type using a SWITCH, then matches the highest "band" value using a VLOOKUP and then an IF to check if the previous running total was less than the highest matched "band" value, calculating and adding the difference if needed.
I've tried to figure out how to calculate the same result when multiple bands are crossed (as in example) but I can't find a way to structure the formula so that it can apply universally down the column using the matched band rate(s), previous running total and new running total values.
Is there a mathematical way to do this or will this require multiple nested IF statements etc or would another approach work better?
I solved this by modifying the formulas on this page. Changing the layout of the bands was a good first move.
Now, column I calculates the value from the current running total (matched from type in column A) and subtracts the value calculated in the same way but using the previous running total to give the amount applicable to the newly entered value on the same row in column H. I've some more testing to do but fairly sure it works correctly. Any other ideas, feel free to suggest!
Provisionally working sheet here: https://docs.google.com/spreadsheets/d/1e2pdyOi7dz_ZA8zfNtsHxieEUb5fiZGpD_FwRvkHyYw/edit?usp=sharing

Data validation drop down list from a range, than only displays values conditionally WITHOUT using a second calculation sheet

I have a function in a data validation drop down list that shows options from a range A2:A30, but I only want it to show options that have a value greater than or equal to 10 in the column over B2:B30. The cell I am referring to is O5.
Example sheet
The purpose/objective is that I have a linear regression formula building projections based on past data about the selected mode, and I don't want the dropdown to be able to select options that have a count less than 10 (because the projection is wildly inaccurate). I would like to do this without creating a second tab or hidden section that populates a second range under those conditions, and then rerouting the data validation to that range.
Any suggestions towards this goal or towards learning about the general idea will be appreciated.
I have come to an indirect solution by manipulating the data in a different way specific to my example sheet. I changed the data validation drop-down range from A2:A30 to A2:A5, and then changed the =unique() formula to a query that fill in the options, the count for that option, and then sorts it ascending so that the top spots are the ones with the most data. Therefore the linear regression will be somewhat limited to the options with better data.
The query is:
=query('Data Sheet'!$A$2:$C, "select A, count(A) where A is not null group by A order by count(A) desc label count(A) ''")
All of the rest of the formulas are built off of that query, including the data validation drop down. It is in my example sheet.

Select value from range based on match

I've got the following set of data and have setup a another table to the right which holds the cost of each location.
The cost column currently I've got =IF(EXACT(B2,"Home"),D2*17.2,D2*0.09), however the cost per kWh can change based on different locations. I want to be able to lookup the cost based on another table which will make things more manageable.
You can put this formula in E2:
=VLOOKUP(B2,$G:$H,2,FALSE)*D2
It will take the value in B2, find it in the G column, take the value from the cell right to that match in the H column. This is the Cost per kWh, so it gets multiplied by D2 to arrive at the cost.
The FALSE is needed to require an exact match.
Drag/copy down the formula to the other cells in the E column.

=MATCH() returns wrong value

Why doesn't this work? I have the share of votes of different Finnish parties in the City of Jyväskylä in every region.
Every row shows one region, every column has the share of votes of every party. I'd like to add a column where Google Spreadsheet would find out which column has the maximum value on that particular row and then return the text on the header row of that column.
In other words I'd want to add "The biggest party column" that would show which party got the biggest share of votes in every region.
I think that should be possible using =max()-function to find out the maximum value, then using =match() function to give the column index number of the cell that has the biggest value on row and finally use =index()-function to return the party's name from header row.
Any ideas what I'm doing wrong?
MATCH needs a third argument of zero for your case (to get an exact match). Change formula to
=INDEX(C$1:M$1,MATCH(MAX(C2:M2),C2:M2,0))

Resources