Hi @Dafini,
Apologies for missing your last response. So I went back and did some further testing to try and work around the aggregation errors. While the sample data is a bit different, I tried to replicate the scenario as best I could with what I have. You can take a look at the Arena view below where I created (once you click on the link, make sure to hit the ‘copy analysis’ button on the left side so that you can gain access to the analysis and see the work that went into this).
Pivot table conditional formatting error
Since QuickSight does not allow you to combine aggregated and non-aggregated fields, we had to find a way to aggregate the carrier name(s)…or in my example, the country names.
I started with creating fields for the total count per region (for you would be per name/user) and then another one for overall total count:
Per Region:
distinctCountOver({Order ID}, [Country], PRE_AGG)
Total Count:
distinctCountOver({Order ID}, [Region], PRE_AGG)
For the percentage, I know you said you switched over to table calculations but here’s the syntax I used to get the percentages on their own:
sum({Count Per Region})/sum({Total Count})
Next, I built a rank for my countries per region. So for you, this would be to rank the carriers per name/user)
denseRank(
[max({Count Per Region}) DESC],
[Region]
)
The last part was the tricky part as we need to figure out a way to aggregate your carrier field so that it can be utilized in the conditional formatting ifelse. To try and stay away from using other fields to aggregate (since I don’t know what your entire dataset looks like), I used the strlenfunction and placed inside a max aggregation so that it provided me with a metric I could use to filter carriers…(in my example, I substituted ‘United States’ for what your ‘CanadaPost’ would be):
max(strlen(Country))
This gave me a unique value of 13 for ‘United States’ as the space in between counts as well. This is where it will be dependent on your carrier options, ideally no other carrier will have the same string length as ‘CANADAPOST’ so that it’s the only one that produces ‘10’. Last step, I setup my ifelse statement to use in the conditional formatting:
ifelse({Country Rank Per Region} = 1 AND {Max String Length} = 13, 1, 0)
So if my country has the highest count and the string length = 13 (which would be ‘United States’), the apply a 1 else 0.
So for the conditional formatting, I setup the column I’d like to highlight, but base it on the conditional formatting calculation and have it color the box if that equals 1. Since this is in a pivot table, make sure you apply to ‘subtotals’ in the ‘Condition’ section.
In my example, I created two tables, the second one I left all the additional testing fields in there so that you can see the expanded logic.
Let us know if this could work for your scenario or if you have any additional questions