concatenate filtered results in google sheets - filter

i am trying to have some of my filtered results joined in the same cell without having to do this in 2 steps (filter the data, then join it). As my data will fluctuate (volume of rows) I want to do this in 1 coded step.
my data:
can be seen here
shown in the spreadsheet are the formula (below), the results I received, the results I am looking for.
among many tries, this was one of them:
=CONCATENATE(filter({A4:A11,E4:E11},F4:F11="Production Management"))

Related

Create a Dynamic Array formula (Excel) to combine multiple results columns into one column that is filtered & sorted using multiple criteria?

The sample data in the image below is collected from a round robin tournament.
There is a Round column,Home team & Away team columns listing who is playing who. A team could be either Home or Away.
For each match in a round (including any "Bye" match) the number of games won for the Home and Away team are recorded in separate columns respectively.
"Ff" = forfeit and has a value of 0. "Bye" result is left blank (at this stage).
Output columns are "Won, Lost, Round".
Required output (shown in the image) is, for any selected team, the top n most-games-won matches (from both Home & Away) sorted in descending order and then the corresponding games lost but sorted in ascending order where the games won are equal. Finally show the rounds where those scores occurred.
These are the challenges I've faced in going from data to output in one step using dynamic array formula:
Collating/Combining the the Win results into 1 column. Likewise the Losses.
Getting the array to ignore blanks or convert "Ff" to 0 without getting #NUM or #VALUE errors.
Ensuring that if I used separate single column arrays the corresponding Loss and Round matched the Win result
Although "Round, Won, Lost" would be acceptable. But I wasn't able to get the Dynamic Array capability to give the required output with this order.
SUMPRODUCT, INDEX(MATCH), SORT(FILTER) functions all hint at a possible one step formula solution.
The solutions are numerous for sorting & filtering where the existing values are already in one column. There was one solution that dealt with 2 columns of values which was somewhat useful How to get the highest values from 2 columns in excel - Stackoverflow 2013
Many other responses are around the use of concatenation, combining/merging array sets, aggregation etc.
My work around solution is to use a Helper Sheet to combine the Wins from the separate results columns and convert blanks & "Ff" to -1. Likewise for Losses. Using the formula for each line
=IF($C5=L$2,IF($F5="",-1,IF($F5="Ff",0,$F5)),IF($D5=L$2,IF($G5="",-1,IF($G5="Ff",0,$G5)),-1))
Example Helper Sheet
To get the final output the Dynamic Array formula was used on the Helper Sheet data
=SORT(FILTER(L$26:N$40,L$26:L$40>=LARGE(L$26:L$40,$J$3),""),{1,2},{-1,1},FALSE)
I'm trying to avoid using pivottable, VBA solutions. Powerquery possible but not preferred.
Apologies for the screenshots but I couldn't work out how to attach the sample spreadsheet file. (Unfortunately Stackoverflow Help didn't help me to/not to do this.)
Based on the comments I changed my answer with a different approach:
=LET(data,A5:F19,
round,INDEX(data,,1),
ha,CHOOSECOLS(data,3,4),
HAwonR,CHOOSECOLS(data,5,6,1),
w,BYROW(ha,LAMBDA(h,IFERROR(XMATCH(L2,h),0))),
clm,CHOOSE(w,{1,2},{2,1}),
srtwon,DROP(REDUCE(0,SEQUENCE(ROWS(data)),LAMBDA(y,z,VSTACK(y,INDEX(HAwonR,z,HSTACK(INDEX(clm,z,),3))))),1),
res,FILTER(srtwon,w),
TAKE(SORT(res,{1,2},{-1,1}),J3))
Old answer:
=LET(data,A5:F19,
round,INDEX(data,,1),
home,INDEX(data,,3),
away,INDEX(data,,4),
HAwonR,CHOOSECOLS(data,5,6,1),
w,MAP(home,away,LAMBDA(h,a,OR(h=L2,a=L2))),
won,FILTER(HAwonR,w),
TAKE(SORT(won,{1,2},{-1,1}),J3))
In your example you selected round 3 for the third result, but that wasn't won, so I guess that was by mistake.
As you can see making use of LET avoids helpers. Let allows you to create names (helpers) that are stored and because you can name them, you can make complex formulas be more readable.
Basically what it does is filter the columns Home, Away and Round (in that order) for either Home or Away equal the team in cell L2. That's sorted column 1 descending and column 2 ascending. Than the number of rows mentioned in cell J3 are displayed from that sorted array.
Here is my solution based on the excellent contribution by #P.b. Thank you much appreciated.
The wins (likewise losses) required mapping the presence, of the team in question, as hT (home team) to the games it won (hG) and adding to that a 2nd mapping of the games it won (aG) when it was the away team (aT). Essentially what was being done on the Helper Sheet. Result was a 1 column array for game wins and a 1 column array for game losses.
In the process I was able to convert the "Ff" text to 0. I attempted without the conversion and it threw an error.
Instead of CHOOSECOLS used HSTACK to create the new array (wins, losses & round) for the FILTER, SORT, TAKE to work on.
If it could be made conciser(?) that is the next challenge. Overall (not just my solution), this exercise has provided greater flexibility and solved the problems stated. I'm happy!
=LET(data,A5:G19,
round,INDEX(data,,1),
hT,INDEX(data,,3),
aT,INDEX(data,,4),
hG,INDEX(data,,6),
aG,INDEX(data,,7),
wins,MAP(hG,
MAP(hT,LAMBDA(h,h=L2)),
LAMBDA(w,t,IF(w="Ff",0,w)*IF(t=TRUE,1,0))) +
MAP(aG,
MAP(aT,LAMBDA(a,a=L2)),
LAMBDA(w,t,IF(w="Ff",0,w)*IF(t=TRUE,1,0))),
losses,MAP(aG,
MAP(hT,LAMBDA(h,h=L2)),
LAMBDA(w,t,IF(w="Ff",0,w)*IF(t=TRUE,1,0))) +
MAP(hG,
MAP(aT,LAMBDA(a,a=L2)),
LAMBDA(w,t,IF(w="Ff",0,w)*IF(t=TRUE,1,0))),
HAwonR,HSTACK(wins,losses,round),
w,MAP(home,away,LAMBDA(h,a,OR(h=L2,a=L2))),
won,FILTER(HAwonR,w),
TAKE(SORT(won,{1,2},{-1,1}),J3))

How to read data using Google query language and update using sheets api, when query doesn't return row numbers?

What I want is to search one row in Google Spreadsheet and Update the value of one column. (When we have a large number of rows)
By looking at the main requirement, it seems easy. Yes of course. There are easy and straight forward ways to do that. But, when we have more data(rows) in spreadsheets around 100,000 rows, the usual methods are very slow. I was able to search for data using Google Query Language and it is a very efficient way (less than 1 sec for more than 50,000 records)
Now Google offers batch update mechanism, and we have to set the range in order to update the data.
But if we use the query api to search the data, we will not get the row number and we don't know where to update. Google offered two independent solutions, but how to combine these solutions efficiently? (Especially for large number of records).
Also, Are there any alternate solutions I missed?
The easiest way is to add a column with row numbers. You can then use query to retrieve the rows, which will contain the row numbers as well.
Another way is to use text finder, whose performance is comparable/better than query.

How to design algorithm to allocate members of overlapping sets so that they are sorted according to specific criteria

I need to write an algorithm (pseudocode is fine) to accomplish the following problem.
We have a list of supermarket grocery stores, say 3,000. We have a footfall rank score for each store from 1 to 3,000. The stores are identified by index numbers.
We have multiple lists of stores (all of which are members of the master list of 3,000 above) for various marketing campaigns which we wish to run; each store may feature only one campaign. The task is to allocate marketing campaigns to stores such that:
each campaign gets as many stores as possible from its demanded list.
the campaigns get the best footfall rank possible and the best footfall stores are shared out between the campaigns as fairly as possible
There may be up to 10 marketing campaigns to allocate and there may be any number of overlaps between them.
I have already created one algorithm shown below. This works successfully to equalise footfall rank but because it goes through the store list in footfall order, it's possible that we run out of stores without satisfying all demand.
The current method is as follows:
Rank the master store list in footfall order
Rank the campaign list in priority order (this makes little difference but anyway)
Take campaign list (1) - does it have all the stores it needs? If yes, go to next campaign and repeat. If not, is this store a member of campaign list (1)? If so, allocate campaign 1 to this store, move to next store. If not, go to next campaign and return to beginning of step 3.
Repeat until all campaigns have been allocated or you have run out of stores.
This method delivers a perfect share of footfall to the different campaigns, but because the overlap between any given campaign list and the master store list is different for each campaign, it's possible for a campaign to run out of stores before it has got all the stores it wanted, even if there are enough - just not enough when you go through them in footfall order sharing them out equallt as this method does.
Code not relevant as I will translate the right flow into JS.
Expected result using current algorithm:
Imagine that campaigns 1 and 2 both want 100 stores. We plot a Venn diagram showing that there are enough stores to satisfy 100 stores for each of 1 and 2 considering all the overlaps.
Desired result: each campaign is allocated 100 stores. Footfall rank is equalised as far as possible given the allocation.
Actual result: Campaign 1 gets 100 stores, campaign 2 gets 84 stores, footfall rank is identical.
Looking at the Excel output, it is possible to swap stores from 1 to 2 such that 2 gets 100 stores and 1 is able to top up from stores that can only carry campaign 1. Footfall rank diverges slightly.

How to merge multiple datasets in long format with missing data in SPSS

I am working on a project compiling data from a longitdinal study with approx 300 participants. The data I have been supplied with is divided into multiple SPSS-files, which all are in "long-format". Each data set contain the longitudinal information for one test. The participants have been measured at 20 time-points, so there is a maximum of 20 observations per participant.
I am to compile all these data sets into one SPSS-file in wide-format.
However, there are multiple challenges when combining these data sets into one data set:
Missing visits are not represented by a row in any of the dataset.
The response rate (i.e. total number of rows) differ between measure.
There are multiple errors in coding of visits (i.e. the "timpeoint" variable is wrong in many of the cases), but i have date of each visit.
To correct for two of these challanges have manually checked in one the databases, and corrected errorous "timepoint"-values, added missing rows. This "mother-database" is now of sound quality.
I was wondering if there is a way to merge the rest of the spss-files with this one, while meeting the following criteria:
Match by ID number.
Match by visit-date, using "mother-database" as a definition of a visit (note that not all visits are available in the data sets i am trying to merge with the "mother-database").
In case of missing data on a visit, add missing values.
In case of missing visit (i.e. no date), add missing values.

Sort Order Using Group Total (SSRS)

I am trying to sort my results by a sub-total. This sub-total was not received from a SQL count, but rather from using the Group Feature to create the stepped report. I've attached an image of what my results look like. In that image, you can see that it's currently ordered/sorted by the Client Number, and then the matter number (which you can't see but isn't really important at this time).
What I want is for it to list the Client's with the most matters first - that's the sub-total. In the image you can see there is one that has 6, so that should come first. The end sort would be Highest Count -> Client Number -> Matter Number.
Any guidance someone can give me would be great. I was trying to figure out how to do the count from the SQL side, but I don't seem to see a way to do a sub-total count of how many matters each client has. I can only count each matter individually, and do a grand total of how many matters were there, total.

Resources