Create a query using existing query
Reading time:
Sometimes it is necessary to perform a complex query using a subquery. In this example, to calculate the average duration from acceptance to closing in an emergency scenario, directly applying the Avg function will yield inaccurate results due to duplicate rows in the denormalized table. To address this issue, one must exclude all duplicate rows before performing any calculations. This can be achieved by creating an initial query with a group by clause to remove duplicates and then using a second query that calls the first query to perform the Avg calculation.
First step, we prepare the initial query that remove all duplicate rows, and save it.
Click on the 'Views'.
Select the view, click on the query we have prepared in precedent step,
Click '+' next to the field name and add it to the dimension or measure.The selected fields will be located on the right side of the screen:
We can sort the dimension and measure by clicking on:
We can customize the aggregation option by clicking on this button, in this instance, we could choose count distinct for "Access Code", and Mean for "Time Acceptance - Closing(min)"
We can add conditions to this new query.
To run an extract, click the 'Execute Query' icon.
To save an extraction, click the 'Save as view' icon.
To clean an extraction, click on the 'Clear Query' icon.