Percent of Total for Distinct Count

I am attempting to make a table that shows the distinct count of resources in one column, and the associated percentages of the whole in another column.

Within my data resources can be spread across multiple groups hence why I am using distinct count.

The calculated field to get the distinct count of resources is distinct_Count(Resource_ID).

When I try to create the % calculated field, I get an error saying that “Adding totals to distinct count aggregations is currently unsupported.”. The calculation for this field is percentOfTotal(distinct_Count(Resource_ID)).

Is there a workaround to get this calculation working? I understand that since resources are in multiple groups, the total percentages will add up to over 100% which is ok for now.

Hello @guhifdgh !

I do you have any other unique attributes for the resource id like another UUID or timestamp? Then you could try something like countOver instead and partition by the unique attribute.

The other way would be doing this in SQL if you are able to do that on your dataset.

Hey Duncan,

When using countOver in the formula below I am getting the expected result. X-Axis Grouping is a calculated field that is determined from a parameter selection by the user.

countOver({Resource_ID}, [{X-Axis Grouping}])

However when I attempt to use that calculation with the percentOfTotal, I am getting the following error: “We encountered an error trying to save your calculated field. Please try creating it again.”

percentOfTotal(countOver({Resource_ID}, [{X-Axis Grouping}]), [{X-Axis Grouping}])

Hello @guhifdgh !

Can you try this:

percentOfTotal(countOver({Resource_ID}, [{X-Axis Grouping}]))

It might be that using a double partition was throwing it off.

I am getting the same “We encountered an error trying to save your calculated field. Please try creating it again.”

Hey @guhifdgh !

Instead of using percentofTotal could you try the following calculated field:
distinctCountOver({resourceID}, [{X-Axis Grouping}], PRE_AGG)/distinctCountOver({resourceID}, [], PRE_AGG)

7 Likes

Hey @guhifdgh !

Were you able to test the calculation above?

Hey @duncan - the formula above worked and did exactly what I was looking for. Thank you!

1 Like

@guhifdgh No problem!

Hey Duncan, I used the above calculated field to get the percentage of distinct resources and its working fine however my requirement is to display the percentage of the latest period and I am currently struggling on that I had posted the details of my problem in this post, could you please help me on this ? How to Calculate Percentage of Resources for the Latest Period in AWS Quick Sight? - Question & Answer - Amazon Quick Sight Community