Nesting Functions

Hello,

Problem: I need to limit duplication of data using a calculation & keep getting errors.

Error: Mismatched aggregation. Custom aggregations can’t contain both aggregate “MAX” and non-aggregated fields “MAX(“questions_asked”)”, in any combination.

Calculation 1:

ifelse({audit} = ‘Completed’, {questions_asked}, null)

Calculation 2:

max({questions_asked}, [location_name])

Calculation Needed:

Combine

ifelseifelse({audit} = ‘Completed’, max({questions_asked}, [{location_name}]), null)

Additional Details:

{audit} = string
{questions_asked} = #
{location_name} = string

How can the calculations be combined?

Thanks,

Can you try this?

maxOver(
ifelse({audit} = ‘Completed’, {questions_asked}, null),
[{location_name}],
PRE_AGG
)

1 Like

Thanks for your reply!

The calculation is valid but the result is the exact same as the current calculation.

ifelseifelse({audit} = ‘Completed’, {questions_asked}, null)

Thanks,

In what visual type are you trying to use the calculated field?

1 Like

The visuals are a table and pivot table. Both produce the same result.

Example:

Data being reviewed is answers from a survey. These answers are Yes, No, N/A only. Each Country has the same survey and the same 3 questions:

Completed Survey

image

How Data Looks Imported

image

USA answered 1 question No. The survey data will appear in the questions_asked with 9 questions instead of 3.

UK answered 2 questions No. The survey data will appear in the questions_asked with 12 questions instead of 3.

{audit_status} = string = status of survey
{questions_asked} = # = total number of survey questions asked
{location_name} = string = location of survey

Calculation 1:

used to remove the duplicated data
max({questions_asked}, [location_name]) - returns a valid and accurate representation of total questions_asked in survey.

Calculation 2:

should be to show all completed surveys & the correct total # of questions asked.

ifelse({audit_status} = ‘Completed’, {questions_asked}, null) - returns an inaccurate number of questions_asked completed status’s and needs to be grouped at the location_name (unique id).

OR

maxOver(ifelse({audit} = ‘Completed’, {questions_asked}, null), [{location_name}], PRE_AGG) returns an inaccurate number of questions_asked completed status’s and needs to be grouped at the location_name (unique id).

Thanks,

Side Note: Query has many joins and is connected to a live data source. It is not optimal to adjust the query.

Do you mean that USA took the survey 3 times and UK took the survey 4 times?

Are you trying to create a table visual that looks like this?
image

1 Like

No, they each took the survey once. The 3 / 4 times shows how the data is duplicated.

Can you show the visual that you’re trying to create so we can work backwards to figure out how to get there? Are you trying to create a table like this?
image

1 Like

The table was to provide a visual for you of how the data is being pulled and duplicated. I need the calculation as specified above to produce DPHO, defects per hundred opportunities. Due to the duplication of data the number is incorrect and I need to be able to group by location_name as this is the only field that is unique.

How does the number of defects or opportunities relate to the survey or questions? How do you want to show DPHO? Do you want to show this number per location in a table or in a KPI?

Take a look at the solution to the question below and see if it helps. It also involved duplicates.

I am hopeful this statement will be more clear:

We need to calculate Defect Per Hundred Opportunities of action items when an audit is completed.

Problem: The query pulls in duplicate data due to need of the report and need is to blend data within the query.

Note: Using count distinct or level aware for location_name will provide provide accurate counts for any field.

Total Questions Asked Calculation: max({questions_asked}, [{location_name}]); produces correct totals

Completed Audits Calculation: ifelse({audit_status} = ‘Completed’, {questions_asked}, null); produces incorrect totals due to duplicate data. When attempting ifelse({audit_status} = ‘Completed’, {Total Questions Asked Calculation}, null) an error is recevied “Error: Mismatched aggregation. Custom aggregations can’t contain both aggregate “MAX” and non-aggregated fields “MAX(“questions_asked”)”, in any combination.”

This calculation didn’t produce correct results: maxOver(ifelse({audit_status} = ‘Completed’, {questions_asked}, null), [{location_name}], PRE_AGG) it provided the same results as ifelse({audit_status} = ‘Completed’, {questions_asked}, null)

Final Calculation Needed: count(questions_asked) / total audit questions asked of a completed audit * 100

Thanks,

This is resolved. The below is the calculation used.

sum(max(
ifelse({audit_status} = ‘Completed’, {questions_asked}, null)
,[location_name]))