# Trouble With "Custom" Calculated Field Type Within Analysis

**URL:** <https://community.amazonquick.com/t/trouble-with-custom-calculated-field-type-within-analysis/4800>\
**Category:** Q&A\
**Tags:** analysis, calculations, quick-sight\
**Created:** [July 19, 2022, 5:58pm UTC](https://community.amazonquick.com/t/trouble-with-custom-calculated-field-type-within-analysis/4800 "2022-07-19T17:58:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![connoranderson](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@connoranderson](https://community.amazonquick.com/u/connoranderson)\
**Post date:** [July 19, 2022, 5:58pm UTC](https://community.amazonquick.com/t/trouble-with-custom-calculated-field-type-within-analysis/4800/1 "2022-07-19T17:58:42Z")

</div>

Hi,

I am creating a calculated field within an analysis. This calculated field uses an ifelse statement to say if sum(field X) \>= 20, then 1, else 0. This new field then appears with “(Custom)” next to it when I drag it into Values in Field Wells. I have several other “(Custom)” calculated fields as well.

I would like to show KPI’s for these fields such as sum and average. However, when I drag these variables into a KPI, I am not given any aggregate options other than “Custom”. And the KPI itself is just a 0 or 1. Whereas when I look at a KPI for a variable that says “(Sum)”, I am able to choose between average, count, median, etc, and get actual KPI values.

Any help is appreciated, thank you!

---

<div class="post-metadata">

**Author:** ![Jesse](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/jesse/32/177_2.png) [@Jesse](https://community.amazonquick.com/u/Jesse)\
**Post date:** [July 19, 2022, 7:55pm UTC](https://community.amazonquick.com/t/trouble-with-custom-calculated-field-type-within-analysis/4800/2 "2022-07-19T19:55:46Z")

</div>

@connoranderson can you provide some more detail on what you are trying to do in business terms? Wondering if you really need the sum inside your calculated field. Also trying to understand what you want to do with those 1’s after. Are you trying to do something like ‘count how many customers who have spent more than $20’? in a KPI?

---

<div class="post-metadata">

**Author:** ![connoranderson](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@connoranderson](https://community.amazonquick.com/u/connoranderson)\
**Post date:** [July 20, 2022, 12:58pm UTC](https://community.amazonquick.com/t/trouble-with-custom-calculated-field-type-within-analysis/4800/3 "2022-07-20T12:58:03Z")

</div>

Hi Jesse,

No problem. So we’re looking at minutes. Specifically how many minutes our staff have spent with each patient working on 3 different task types. I have 3 pivot tables for each of the 3 task types with patients as rows. The first column is “Duration\_Minutes” which comes from our dataset. Within the pivot, this column shows for each patient the sum of their total minutes associated with that task type. Then I would like a second column that uses my ifelse statement above to say if Duration\_Minutes \>= 20, then give a 1, else give a 0.

You are right, I didn’t think I would need to use a sum within the ifelse either, but when I execute that formula without the sum I can see that many patients who have over 20 in Duration\_Minutes are not given a 1. I think this is because it’s looking at rows in our dataset to see if the patient has at least 1 record where Duration\_Minutes is \>= to 20, not looking at the summed value under Duration\_Minutes in the pivot.

To your last question, yes ultimately I’d like to count up the 1’s resulting from that ifelse to say how many patients have at least 20 minutes for the 3 task types.

---

<div class="post-metadata">

**Author:** ![robdhondt](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/robdhondt/32/194_2.png) [@robdhondt](https://community.amazonquick.com/u/robdhondt)\
**Post date:** [July 21, 2022, 1:30pm UTC](https://community.amazonquick.com/t/trouble-with-custom-calculated-field-type-within-analysis/4800/4 "2022-07-21T13:30:23Z")

</div>

Hi @connoranderson -

**Custom Calculated Field**  
Quick Sight applies the “Custom” label to [Aggregate functions](https://docs.aws.amazon.com/quicksight/latest/user/calculated-field-aggregations.html). You’ve already specified the aggregation for the visual in your calculated field and the UI will use that.

For your use case you’ll want to use a [Level Aware Calculation](https://docs.aws.amazon.com/quicksight/latest/user/level-aware-calculations.html)

It would look something like this for your use case.

1. Use a LAC-A to sum the minutes at the same level as your group by.  
c\_visit\_duration\_LAC-A

```auto
sum(Duration_Minutes,[{visit_id}])

```

1. You can use this calculated field in your visual for further aggregation because LAC-A and LAC-W functions are performed before your visual aggregation [(order of evaluation)](https://docs.aws.amazon.com/quicksight/latest/user/order-of-evaluation-quicksight.html)

c\_visit\_greater\_than\_20\_flg

```auto
ifelse({c_visit_duration_LAC-A}>=20,1,0)

```

---

<div class="post-metadata">

**Author:** ![connoranderson](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@connoranderson](https://community.amazonquick.com/u/connoranderson)\
**Post date:** [July 27, 2022, 1:22pm UTC](https://community.amazonquick.com/t/trouble-with-custom-calculated-field-type-within-analysis/4800/5 "2022-07-27T13:22:00Z")

</div>

This worked, thanks a lot!!
