Summing Over an IFELSE Column

I have a data set like the following:

Provider Name || Provider Specialty || Apt Length 1 || Apt Length 2
Dr. A Cardiology 30 15
Dr. B Oncology 15 20

I have created a calculated field that tells me if the Apt Length 1 is divisible by Apt Length 2 (ie. Could I divide some of the providers “slots” for length 1 into equal segments for length 2 to make more room if needed). This works like this:

Provider Name || Provider Specialty || Apt Length 1 || Apt Length 2 || Divisible Flag
Dr. A Cardiology 30 15 1
Dr. B Oncology 15 20 0

The syntax in Quicksight for this Divisible Flag is:
ifelse(mod(Apt Length 1, Apt Length 2)=0, 1, 0)

I have several hundred providers in the file each broken into ~10 specialties. I am trying to roll this column up by specialty and see how many doctors in each specialty have divisible appointment lengths to return something like:
Specialty || # with Divisible Apts || # without Divisible Apts || % with Divisible Apts
Cardiology 10 10 50%
Oncology 5 0 100%

I tried to write a SUMIF over the current IFELSE function I have above and was given an error. If I try to just sum the column in a table in Quick Sight it doesn’t let me as it is a “custom” aggregate type. Is there a way to do this type of calculation?

Hi @earevalo, welcome to the Quick Sight Community, to accomplish the aggregation and calculation of your Divisible Flag, especially considering the errors you’re encountering with SUMIF, you will need to use alternative approaches to calculate the total count of providers with divisible appointment lengths by specialty, and similarly, those without. This will help you roll up the data as needed.

Approach to Solving Your Requirement:

Step 1: Using Calculated Fields

Firstly, ensure that your existing calculated field for the Divisible Flag is working correctly:

ifelse(mod(`Apt Length 1`, `Apt Length 2`) = 0, 1, 0)

To accomplish the aggregation and calculation of your Divisible Flag in AWS Quick Sight, especially considering the errors you’re encountering with SUMIF, you will need to use alternative approaches to calculate the total count of providers with divisible appointment lengths by specialty, and similarly, those without. This will help you roll up the data as needed.

Approach to Solving Your Requirement:

Step 1: Using Calculated Fields

Firstly, ensure that your existing calculated field for the Divisible Flag is working correctly:

ifelse(mod(`Apt Length 1`, `Apt Length 2`) = 0, 1, 0)

This is correct and should effectively determine if Apt Length 1 is divisible by Apt Length 2.

Step 2: Creating Count Calculated Fields

Since Quick Sight does not support SUMIF directly in the way traditional spreadsheet tools do, you’ll need to create additional calculated fields to count the divisible and non-divisible appointment lengths. You can use the existing Divisible Flag to create these.

  1. Count of Divisible Appointments by Specialty:
sum(ifelse(`Divisible Flag` = 1, 1, 0))
  1. Count of Non-Divisible Appointments by Specialty :
sum(ifelse(`Divisible Flag` = 0, 1, 0))

This will count appointments where the flag is 0 (non-divisible).

Step 3: Percentage Calculation

Create another calculated field to find the percentage of divisible appointments:

div(sum(ifelse(`Divisible Flag` = 1, 1, 0)), count(`Provider Name`)) * 100

This formula calculates the percentage of providers within each specialty that have divisible appointment lengths.

Step 4: Using Visuals to Display the Data

With these calculated fields, you can now create a table or another visual type in Quick Sight that displays these metrics:

  • Drag the Provider Specialty to your visual’s group by or dimension area.
  • Add the new calculated fields (Count of Divisible Appointments by Specialty, Count of Non-Divisible Appointments by Specialty, and Percentage Calculation) to the value or measure area of your visual.

This setup will allow you to view the count and percentage of divisible and non-divisible appointments by specialty as you described.

Additional Notes:

  • Ensure Data Types: Check the data types of your fields, particularly the appointment lengths, to ensure they are numerical and thus suitable for mathematical operations.
  • Debugging: If errors continue to occur, double-check your syntax and field names for typos or syntax errors, which are common culprits in such situations.
  • Performance: When working with large datasets or complex calculations, consider the performance implications and test the responsiveness of your dashboards.

By following these steps, you should be able to effectively aggregate and analyze the divisibility of appointment lengths across specialties in AWS Quick Sight.

This formula calculates the percentage of providers within each specialty that have divisible appointment lengths.

Step 4: Using Visuals to Display the Data

With these calculated fields, you can now create a table or another visual type in Quick Sight that displays these metrics:

  • Drag the Provider Specialty to your visual’s group by or dimension area.
  • Add the new calculated fields (Count of Divisible Appointments by Specialty, Count of Non-Divisible Appointments by Specialty, and Percentage Calculation) to the value or measure area of your visual.

This setup will allow you to view the count and percentage of divisible and non-divisible appointments by specialty as you described.

Additional Notes:

  • Ensure Data Types: Check the data types of your fields, particularly the appointment lengths, to ensure they are numerical and thus suitable for mathematical operations.
  • Debugging: If errors continue to occur, double-check your syntax and field names for typos or syntax errors, which are common culprits in such situations.
  • Performance: When working with large datasets or complex calculations, consider the performance implications and test the responsiveness of your dashboards.

By following these steps, you should be able to effectively aggregate and analyze the divisibility of appointment lengths across specialties in AWS Quick Sight.