# How to include unique count option in table

**URL:** <https://community.glideapps.com/t/how-to-include-unique-count-option-in-table/79969>\
**Category:** Ask for Help\
**Created:** [February 10, 2025, 9:48pm UTC](https://community.glideapps.com/t/how-to-include-unique-count-option-in-table/79969 "2025-02-10T21:48:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ina1](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/ina1/32/84873_2.png) [@Ina1](https://community.glideapps.com/u/Ina1)\
**Post date:** [February 10, 2025, 9:48pm UTC](https://community.glideapps.com/t/how-to-include-unique-count-option-in-table/79969/1 "2025-02-10T21:48:03Z")

</div>

I have a table that has multiple product variation e.g. Black Red Blue and for each variation row there’s a corresponding problem column. If a variant has multiple problem it is listed in another column under problem 1 problem 2 and so on. I want to count all unique problems for the product  
e.g:  
broken lid - (totalnumberofbrokenlid)/(totalcountofproblems)

I also want a separate data counting all the total problems for each variations. Right now im just manually entering and counting all the data and I want to automate this process can someone please help me.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [February 11, 2025, 12:04am UTC](https://community.glideapps.com/t/how-to-include-unique-count-option-in-table/79969/2 "2025-02-11T00:04:17Z")

</div>

First, I would suggest a structure like this. If you have more problems for a variation than your current columns count would support, you have to add more columns?

### Table: `Product`

| ProductID | ProductName |
| --- | --- |
| PR001 | Widget |

### Table: `ProductVariation`

| VariationID | ProductID | VariationName |
| --- | --- | --- |
| PV001 | PR001 | Black |
| PV002 | PR001 | Red |
| PV003 | PR001 | Blue |

### Table: `ProductProblems`

| ProblemID | VariationID | ProblemDescription |
| --- | --- | --- |
| PP001 | PV001 | Broken lid |
| PP002 | PV001 | Scratched |
| PP003 | PV002 | Broken lid |
| PP004 | PV002 | Dented |
| PP005 | PV003 | Scratched |
| PP006 | PV003 | Dented |
| PP007 | PV001 | Scratched |

Then:

- In the Product Variation table, create a multiple relation to the Product Problems table using the Product Variation ID.
- Create a rollup, you will get the total problems for each variation.
- Create a joined list column to get a list of problems for each variation.
- In the Products table, create a multiple relation to the Product Variations table using the Product ID.
- Create a joined list column to get a list of problems for all variations. You’ll get something like this: “Broken lid, Scratched, Broken lid, Dented, Scratched, Dented, Scratched”.
- Add a JavaScript column like this.

```auto
function countProblems(problems) {
    // Split the comma-delimited string into an array
    const problemArray = problems.split(', ');

    // Create an object to store the count of each problem
    const problemCount = {};

    // Iterate over the array and count each problem
    problemArray.forEach(problem => {
        problemCount[problem] = (problemCount[problem] || 0) + 1;
    });

    // Calculate the total number of problems
    const totalProblems = problemArray.length;

    // Create an array to store the result strings
    const result = [];

    // Iterate over the problemCount object to create the result strings
    for (const problem in problemCount) {
        result.push(`${problem} - ${problemCount[problem]}/${totalProblems}`);
    }

    // Sort the result array alphabetically
    result.sort();

    // Return the result as a single string
    return result.join('\n');
}

return countProblems(p1)

```

With p1 being the joined list in the Products table.

 ![CleanShot 2025-02-11 at 07.03.48](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/b/0b5ed0727cd13a593d8ef442191d7968feebcff5.png)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [February 18, 2025, 12:04am UTC](https://community.glideapps.com/t/how-to-include-unique-count-option-in-table/79969/3 "2025-02-18T00:04:48Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
