Calculating an average within a visual

Hi, struggling here and, apologies, I can’t quickly create a sample board to replicate as all the data is confidential and there a lot of fields included in the original query.

What we have is a client who has submitted 20 projects. SubmittedAt is just a count of the distinct project submission dates.

CreditsUsedNew is a number associated with a project of how many credits as associated. Nearly all projects in this case were one credit but one was more hence, there are 23 credits here summed against the 20 submissions.

Separate to this are events. Each edit event within a project has a time associated to edit i.e V1 video took 2 hours, V2 took 1 hours etc.

‘Calc- Total Time to edit’ is a ‘sum({Calc - Time to Edit in Hours})’. So, here I’m adding up all the versions and their associated editing time which stacks up fine and, in this case is 36 hours across all the versions within the 20 projects and 23 credits booked. (this ‘Calc - time to edit in hours’ within the calc is just the edit time per version divided by 60 as it’s in minutes initially).

So all I actually want to do here is work out average time to edit each credit which is 36/23=1.56

Whenever, I try and divide one by the other, I get the issue with mixing aggregated and non-aggregated data so I tried this below but whilst the answer is somewhere in ballpark, it’s not accurate i.e 1.74 in this case. (The ‘readableId’ here is the unique ID against each project)

(sumOver({Calc - Time to Edit in Hours}, [readableId], PRE_AGG)/CreditUsedNew)

Any ideas?
Thanks!

Hi @TurboSlippers,

I’ve mocked up some data (see below) and re-created your calculated fields and table. If I use the following calculated field I am able to generate the correct values for “Calc - Average edit time per project”:
sum({Calc - Time to Edit in Hours})/sum(CreditUsedNew)

When you received the “mixing aggregated and non-aggregated data” error it may have been because the aggregation wasn’t being applied to the CreditUserNew field, e.g. the following gives me the same error as it is mixing aggregated with non-aggregated numerators/denominators:
sum({Calc - Time to Edit in Hours})/CreditUsedNew

Many Thanks,
Andrew

Projects Table

Name Project SubmittedAt CreditUsedNew
aname A 01/01/2024 1
aname B 02/01/2024 1
aname C 03/01/2024 1
aname D 04/01/2024 1
aname E 05/01/2024 1
aname F 06/01/2024 1
aname G 07/01/2024 1
aname H 08/01/2024 1
aname I 09/01/2024 1
aname J 10/01/2024 1
aname K 11/01/2024 2
aname L 12/01/2024 1
aname M 13/01/2024 1
aname N 14/01/2024 1
aname O 15/01/2024 1
aname P 16/01/2024 2
aname Q 17/01/2024 1
aname R 18/01/2024 1
aname S 19/01/2024 2
aname T 20/01/2024 1
bname A1 01/01/2024 1
bname A2 02/01/2024 1
bname A3 03/01/2024 1
bname A4 04/01/2024 1
bname A5 05/01/2024 1
bname A6 06/01/2024 2
bname A7 07/01/2024 2
bname A8 08/01/2024 1
bname A9 09/01/2024 1
bname A10 10/01/2024 1
bname A11 11/01/2024 2
bname A12 12/01/2024 1
bname A13 13/01/2024 1
bname A14 14/01/2024 1
bname A15 15/01/2024 1
bname A16 16/01/2024 2
bname A17 17/01/2024 1
bname A18 18/01/2024 1
bname A19 19/01/2024 2
bname A20 20/01/2024 1

Events Table

Project Event TimeToEditMinutes
A V1 60
B V1 120
C V1 300
D V1 480
E V1 180
F V1 240
G V1 60
H V1 120
I V1 180
J V1 420
K V1 540
L V1 60
M V1 180
N V1 360
O V1 420
P V1 60
Q V1 120
R V1 60
S V1 120
T V1 60
A1 V2 60
A2 V2 120
A3 V2 300
A4 V2 480
A5 V2 180
A6 V2 240
A7 V2 60
A8 V2 120
A9 V2 180
A10 V2 420
A11 V2 60
A12 V2 120
A13 V2 300
A14 V2 480
A15 V2 180
A16 V2 240
A17 V2 60
A18 V2 120
A19 V2 180
A20 V2 420

Hi @Turboslippers, did this solution work for you? I am marking this reply as, “Solution,” but let us know if this is not resolved. Thanks for posting your questions on the QuickSight Community!

Also, here is a good article on level-aware calculations. It includes a section on mismatched aggregation errors.

Nice one, very very much appreciated @abacon ! That works perfectly…however, this now creates a new problem (the last on in the chain though)

The end goal is work out a rough profit margin per client. To that end I have to work out the production cost first so I have;

Calc - Production cost - This is calculated field using a switch where X, Y etc are the hourly production costs

switch(contentRegion,
“US”, X,
“ASIA”, Y,
“EU”, Z,
“AU”,A,
0)

To work out the production cost I am then using ‘{Production Cost per hour}*{Calc - Average edit time per credit}’

I then get another mismatched aggregation though…

And then, after that I want to do the margin which would be (‘credit cost’-‘calc - production cost’)/‘credit cost’

I suspect I’ll get another mismatch here. You can tell here my brain struggles with aggregation :slight_smile:

1 Like