Looking for tips please for the best way to tackle this seemingly easy challenge:
Consider my App will have a data sheet, like the one below:
The goal is to allow the user to
Select which attributes (top row) are of interest (1 or more)
Select the values of those attributes to use as a filter (1 or more)
then show the count of people that match.
e.g. If I am interested in people with favorite flavor vanilla then the count is 2.
e.g. if I am interested in YOUNG people with favorite flavor vanilla then the count is 1.
A key restriction is that in reality the table of data is not based on a fixed database. Users will need to be able to work with a fresh table (in practice I will import this into the Google sheet). The layout of the table will be the same (people down the side and attributes across the top), however the number & definition of the attributes may vary considerably.
Is there a way to achieve this without formulas in the Google sheet?
I have managed the first hurdle, selecting attributes and picking which of their values are needed. But once the filters are defined, Iām getting stuck with the final count step. Is it too much for Glide since relations cannot easily be filtered without creating template columns? That doesnāt seem feasible because of the scale.
If the best option is using a Google formula, can anyone suggest the formula please?!
To count the number of relations that are created you can use the rollup column. That should help you deal with this without any Google Sheets formulae.
Create a separate table where you have only 1 row to store the choices in user-specific columns. Letās say you have a āColor choiceā column.
Then bring that color choice column over to the main table using a single value column.
Add an If Then Else column to take care of the empty choices, letās call it Color ITE. If Color choice is empty then choose the Color from the original Color, else Color choice.
After having all those Color ITE, Age ITE, Flavor ITE column then you can make a final ITE column to see if the whole row matches the filter. Letās call it āFinal ITEā.
If Color is not Color ITE then false, Age is not Age ITE then false, ā¦, else true.
Make a template column with the value ātrueā, relating that to the whole Final ITE column and add a rollup to count the total number of matches.
This something that I do in my apps all the time. I described the technique that I use below:
Essentially it boils down to dynamically generating a multi-relation for displaying the filtered results, and doing a rollup through that relation to get a dynamic count. It works very well.
Yes, I have used that option myself and it works well for a limited number of fixed attributes. But I donāt think it works here. In this case, I may have 50 attributes and the names of the attributes will change. How do you get the name of the attribute into the concatenated template when so much is fluid?
Yes, as I mentioned in my original post, it works well for filtering with up to 4 or 5 attributes. After that it can get a little cumbersome. Although, that really depends on whether or not you need to provide an āAllā option in your choice components. If you donāt, it should scale up quite well - although you do need to predefine which columns will be used for filtering in order to create the template columns.
It is also possible to dynamically generate the options for the choice components based on the existing data. That can be done as follows:
Ensure that you have a Row ID column in the table that contains your data
For each of the columns that will be used, do the following:
Create a single relation that joins that column to itself
Create a lookup through that relation that fetches the Row ID
Now create an if-then-else column that compares the value in the lookup column to the actual Row ID
For any that match, return true
You can then use that column to filter the list in a choice component
Again, it will mean quite a few columns if you have a large number of filters to apply, but it will work.
Yes, thatās true. In reality the people are patients. The attributes make up a range of descriptors. All the factors that go into making a treatment decision. As you can imagine, experts need the flexibility to select a few of those factors and filter on some values of eachā¦
Well I think I found an alternative solution that is quite efficient.
Put the data into a sheet called āDataā
Create a new Google sheet called āChoicesā with identical headers as the Data sheet, e.g. by using the formula in A1 '=Unique(Data!A1:Z1) - this is good for 26 headers.
Now create a form button in Glide with new rows created in the Choices sheet (under the headers).
I imagine a form with 26 choice components. Each component has the title Attribute1, Attribute2, etc. The data source should be successive columns in the Data Sheet. The destination column should be the respective column in the Choices sheet. In this way, a new row is created containing 1 filter option per attribute.
Create a new Google Sheet called Results. As in step(2) ensure the 1st row has identical headers.
In cell A2 of the the Results sheet we now apply the filters to the original data set using the simple formula: =Filter(Data!A2:Z,Data!A2:A = Choices!A2, Data!B2:B = Choices!B2)
The formula is shown for the first 2 attributes A and B but the rest of the 26 can be added respectively. Finally a roll-up column will deliver the count.
If more than one filter option needs to be considered then it is possible to add another row of filter options using the form component. The formula in (6) then just needs to have extra conditions added. I admit I havenāt worked out the formula that accounts for a āFilter 1 or Filter 2ā but it should be possible.
And the beauty of this approach is that it does not even use a single relation or a single template component!
Iām going to drop this in as an excellent resource for anyone that needs help to generate the Query formula in your Google sheet. I have installed the ad in and it works really well. The only downside is that you cannot have a query field that is an empty cell, but it works for most instances.