# Count in one calculated field

**URL:** <https://community.amazonquick.com/t/count-in-one-calculated-field/13509>\
**Category:** Q&A\
**Tags:** calculations, quick-sight\
**Created:** [May 16, 2023, 2:47pm UTC](https://community.amazonquick.com/t/count-in-one-calculated-field/13509 "2023-05-16T14:47:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![harsh13799](https://avatars.discourse-cdn.com/v4/letter/h/e99b99/32.png) [@harsh13799](https://community.amazonquick.com/u/harsh13799)\
**Post date:** [May 16, 2023, 2:47pm UTC](https://community.amazonquick.com/t/count-in-one-calculated-field/13509/1 "2023-05-16T14:47:08Z")

</div>

Hi, I need help with the below example.

I am using CMSUSERID & RESOURCEID. based on that I need to count as described in the image.  
Currently, It is giving me a total count of 1(min) which should be the total count(i.e. 1+1+5+11+2+3+1+2…).

 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/2X/7/7f970145135c88cb08d1f720ee90a4ab433cc610.jpeg)

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Max](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/max/32/2288_2.png) [@Max](https://community.amazonquick.com/u/Max)\
**Post date:** [May 16, 2023, 7:33pm UTC](https://community.amazonquick.com/t/count-in-one-calculated-field/13509/2 "2023-05-16T19:33:57Z")

</div>

I believe you need to partition by resourceID.

```auto
distinctCountOver({RESOURCEID},[{RESOURCEID}],PRE_AGG)

```

---

<div class="post-metadata">

**Author:** ![harsh13799](https://avatars.discourse-cdn.com/v4/letter/h/e99b99/32.png) [@harsh13799](https://community.amazonquick.com/u/harsh13799)\
**Post date:** [May 17, 2023, 12:48pm UTC](https://community.amazonquick.com/t/count-in-one-calculated-field/13509/3 "2023-05-17T12:48:02Z")

</div>

@Max your calculated field gives me a total count of 1520. I need the total no of distinct resources launched by district users. So, if you see in the below image and example.

User1 - `9e4 (1),`  
User2 -` 538 (1),`  
User3 -

```auto
538 (1), 
b48 (1),
c22 (1),
c2e (1), 
f5c (5 times attempted, but as it is unique I need to count it as 1)

```

**---- subtotal should be 5 ----**  
User4 -

```auto
ba8 (2 times attempted, but as it is unique I need to count it as 1)
c227 (2 times attempted, but as it is unique I need to count it as 1)

```

**---- subtotal should be 2 ----**

So, total count 1 +1 + 5 + 2…

 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/2X/5/5e730b90f012f4b66766bcb82da178588bc5cb41.png)

---

<div class="post-metadata">

**Author:** ![harsh13799](https://avatars.discourse-cdn.com/v4/letter/h/e99b99/32.png) [@harsh13799](https://community.amazonquick.com/u/harsh13799)\
**Post date:** [May 19, 2023, 1:11pm UTC](https://community.amazonquick.com/t/count-in-one-calculated-field/13509/4 "2023-05-19T13:11:51Z")

</div>

is this visual and count achievable or not? 😐

---

<div class="post-metadata">

**Author:** ![Max](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/max/32/2288_2.png) [@Max](https://community.amazonquick.com/u/Max)\
**Post date:** [June 6, 2023, 12:58pm UTC](https://community.amazonquick.com/t/count-in-one-calculated-field/13509/5 "2023-06-06T12:58:29Z")

</div>

Is it just then partitioned by user?

`distinctCountOver({RESOURCEID},[{CMSUSERID}],PRE_AGG)`

---

<div class="post-metadata">

**Author:** ![harsh13799](https://avatars.discourse-cdn.com/v4/letter/h/e99b99/32.png) [@harsh13799](https://community.amazonquick.com/u/harsh13799)\
**Post date:** [June 8, 2023, 6:08am UTC](https://community.amazonquick.com/t/count-in-one-calculated-field/13509/6 "2023-06-08T06:08:43Z")

</div>

Yes, You are right. but I need a total count in just one calculated field as I have to compare it with other counts.

using the below formula I am getting 533. But As I am using POST\_AGG\_FILTER, I am not able to manage the count in one calculated field.

`sumOver(distinct_count(RESOURCEID), [CMSUSERID], POST_AGG_FILTER)` - #test1  
`distinctCountOver({RESOURCEID},[{CMSUSERID}],PRE_AGG)` - #test2

Is there any way? Refer to the below screenshot. You can refer to the first screenshot also for better understanding.

 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/2X/3/3ee8d5806fb9c668beb36f6004c5ef4e176edc36.png)

---

<div class="post-metadata">

**Author:** ![Max](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/max/32/2288_2.png) [@Max](https://community.amazonquick.com/u/Max)\
**Post date:** [June 8, 2023, 1:52pm UTC](https://community.amazonquick.com/t/count-in-one-calculated-field/13509/7 "2023-06-08T13:52:47Z")

</div>

What do you mean “manage the count in one calculated field”?

Is one correct but you can’t use it because of aggregations?

---

<div class="post-metadata">

**Author:** ![harsh13799](https://avatars.discourse-cdn.com/v4/letter/h/e99b99/32.png) [@harsh13799](https://community.amazonquick.com/u/harsh13799)\
**Post date:** [June 8, 2023, 2:06pm UTC](https://community.amazonquick.com/t/count-in-one-calculated-field/13509/8 "2023-06-08T14:06:39Z")

</div>

manage the count in one calculated field means, I need to divide that count(533) by total user attempted resource count(1520). So, the as a final output I need the value in percentage.

So, If I use the #test1 with cmsuserid then it is giving me total count as 533. But I need that count without mapping the calculated field #test1 with cmsuserid.

---

<div class="post-metadata">

**Author:** ![Max](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/max/32/2288_2.png) [@Max](https://community.amazonquick.com/u/Max)\
**Post date:** [June 8, 2023, 2:10pm UTC](https://community.amazonquick.com/t/count-in-one-calculated-field/13509/9 "2023-06-08T14:10:16Z")

</div>

Something like this?

```auto
sumOver(distinct_count({session_id}), [{client_id}], POST_AGG_FILTER)/distinct_count({client_id})

```

If you use PRE\_AGG you can use it in like a KPI and not have to reference cmsuserid
