How to calculate KPI as Worked Hours divided by unique Apas after a join in QuickSight?

I’m having trouble creating a bar chart in QuickSight.

Here’s the situation:
I have one table with airport employees (with fields: Employee, Day, Month, Year, Airport, Worked Hours) and another table with airports (with fields: Airport, Month, Year, Apas). I want to calculate a KPI: Worked Hours divided by Apas.

What I’ve done is create a dataset with a join on Airport, Month, and Year. This gives me a combined dataset, but due to the different levels of aggregation, the Apa values get duplicated for each employee in the same airport and same Month and Year.

So I end up with a table like this:

My goal is to create a Bar Chart where:

  • X-axis = Airports
  • Y-axis = Worked Hours / Apas

For example, if I filter for two months (e.g., February and March), the calculation should be:

(Sum of all worked hours from all employees in Feb and Mar) / (4 + 5)

How can I build this measure correctly?

I’ve created the following calculated field:

sum({Hours}) / sumOver(avg(apas), [Airport, Month, Year])

This seems to work correctly when I display it in a table visual grouped by Airport, Month, and Year. However, when I switch to a bar chart and try to remove Year and Month, the visual returns an error.

Thanks in advance!

Hi @RodrigoDiaz and welcome to the QuickSight community!
Since you’re already filtering down the months, what happens if you remove ‘Month’ and ‘Year’ from your calculated field..would that resolve the error from showing up while still providing the correct information?

If this does not work, it may be more helpful to assist further if you’re able to upload a copy of your analysis (with anonymized data) to the QuickSight Arena view since I don’t have a sample dataset that’s similar to run tests on. Here’s some additional information on how to set that up:

Hi @Brett , thanks for replying to my question.

I’ve created an analysis in the console so you can take a look at the data.

https://community.amazonquicksight.com#Arena-dashboardId=cc1d1e04-e280-4d3d-8dff-178de1e67cc1&authorId=CU-24209

As you can see, in the table on the right the data is displayed correctly and the KPI column shows the correct value I want the chart to reflect

The problem is that if I remove the aggregation by Month, the chart no longer works as expected.

I’ve done the calculations that should appear in the chart when I filter by each of the months, and they are as follows:

Thanks a lot!
Best regards!

Hi everyone!
I managed to solve the issue. This calculated field does exactly what I needed:
sum(Hours)/sum(min(Apa, [Airport, Month, Year]))

Thanks a lot anyway!
Best regards