Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Using Tap Forms › Group summaries
Tagged: sums of fields
- This topic has 4 replies, 3 voices, and was last updated 1 month ago by Glen Forister.
-
AuthorPosts
-
November 15, 2024 at 10:57 AM #51305
Glen ForisterParticipantIn the attached is my data with “show group summaries” selected.
What I would like to have is a way to show the group summaries of each column (field) which is calculated to include the numbers of unique names for each field
For example, how many different Class names, different Order names, different Family names, different Genus names, different Sp names.
If that can’t be done, how do I get that information. It doesn’t have to show up on the screen but can I run a script to show me the results?
I can’t write scripts so I would need help here.
Attachments:
You must be logged in to view attached files.November 16, 2024 at 9:13 PM #51309
JScottAParticipantGlen, I have not tested the answer below, but I hope it helps you. It is from the unofficial custom GPT, Tap Forms 5 Assistant. I suggest you work on a copy of your database when testing this. Good luck!
To calculate and display the number of unique values for each field (e.g., “Class,” “Order,” “Family,” etc.) in your Tap Forms database, you have two options: either use the app’s built-in features for a manual method or run a script.
Option 1: Manual Method Using Export and External Analysis
1.Export the Data:
•Use Tap Forms’ export functionality to export your data as a CSV file. Instructions for exporting are on page 126 of the Tap Forms manual .
2.Analyze in Excel/Spreadsheet:
•Open the CSV in Excel or another spreadsheet tool.
•Use the “Remove Duplicates” feature for each column to count unique entries.
Option 2: JavaScript Script in Tap Forms
If you’d prefer an automated method, you can use Tap Forms’ scripting functionality (JavaScript API) to calculate the unique values for each field. Here’s a sample script you can use:
Sample Script
// This script calculates unique values for specified fields in the current form.
function uniqueValueCounts() {
var form = document.getFormNamed(‘Museum needs’); // Replace with your form’s name
var fields = [‘Class’, ‘Order’, ‘Family’, ‘Genus’, ‘Sp’]; // Replace with your field names
var result = “”;
fields.forEach(function(fieldName) {
var field = form.getFieldNamed(fieldName);
var records = form.getRecords();
var uniqueValues = {};
records.forEach(function(record) {
var value = record.getFieldValue(field);
if (value) uniqueValues[value] = true;
});
result += fieldName + “: ” + Object.keys(uniqueValues).length + ” unique values\n”;
});
return result;
}
var output = uniqueValueCounts();
console.log(output);
alert(output); // Displays the result in an alert box
How to Use the Script
1.Go to the Scripts section in Tap Forms and create a new script.
2.Copy and paste the above JavaScript code.
3.Modify the form and field names to match your data.
4.Run the script.
The output will display the unique value counts for each field in an alert box and in the console.
For additional details on scripting in Tap Forms, refer to the Tap Forms Scripting 101 Guide.
If you need further guidance or customization of the script, feel free to ask!
November 17, 2024 at 1:34 AM #51310
Daniel LeuParticipantThe Javascript API doesn’t provide a way to work on groups. The script posted by JScott shows results on all records. This could be enhanced if you can define how the records are grouped.
Another option would be to work on the current saved search. This would mean that you create a saved search for each group. Then you could replace
var records = form.getRecords();
withvar records = search.getRecords();
to get the results on the currently selected saved search.Oh, ignore the
alert(output)
command in the script since this is not supported. You could useUtils.alertWithMessage()
, but that’s not designed to display multi-line results. The console is your friend.November 17, 2024 at 10:47 AM #51311
Glen ForisterParticipantThanks, I took the easy out and got my answers by exporting and using a spreadsheet to remove duplicates. Interesting way to attack that problem. I will try the script at a later date when I have a day to devote to that.
BTW, this brings up the problem of using a Form Copy to test the scripts. The copy doesn’t have any data, and so that has to be imported via CSV file.
The problem with that is the possibility of a missed comma in the data. I discovered that when I use a field with a Pick List (Multi-Value Popover) with more than one item, a comma is inserted. That creates problems with exporting and using CSV files. I tried to find a way to substitute something else like ” – “, or semicolon etc., but I couldn’t find a way to do that.
Any suggestions?
-
AuthorPosts
You must be logged in to reply to this topic.