Analytical query vs grouped query -> calculate field

Hi guys,

I have an analytical query with more than 1 million rows per day.
When I group the query fields by different customer, the query result does not change because each line becomes unique.
When I take the grouped query to quick sight, I cannot validate whether the number of different customers in the grouped query is the same as in the analytical query.
I notice that when I take the grouped query to quick sight, I cannot create calculated fields in an already aggregated field. I’m having difficulty validating whether the values ​​are correct.

How do you usually do it?
Thanks

Hi @July
can you please elaborate on your question and bring some samples?
BR

Hi ErikG,

The query is a sales funnel. If the query is grouped, Quick Sight returns a different value compared to the same analytical query. For example, if I put the total_cupons field as sum, the value looks strange. If I add it in Quick Sight by count distinct, it always shows the value 1. I don’t know if it’s correct to group the data first or leave it to Quick Sight to do this.

Ex:

SELECT
COUNT(DISTINCT c.id) AS total_coupons,
COUNT(DISTINCT s.id) AS total_simulates,
COUNT(DISTINCT e.id) AS total_effective,
COUNT(DISTINCT customer_id) AS total_customers,
date,
category,
product
FROM coupon c
LEFT JOIN simulates s ON c.coupon_id = s.coupon_id
LEFT JOIN effective e ON s.simulate_id = e.simulate_id
GROUP BY date, category, product;

Tks

Hi @July
the SQL is you QS dataset definition?
Where is QS showing value 1?
Can you share the QS analysis?
I would leave the group to QS.

SELECT
c.id AS coupons,
s.id AS simulates,
e.id AS effective,
customer_id AS customers,
date,
category,
product
FROM coupon c
LEFT JOIN simulates s ON c.coupon_id = s.coupon_id
LEFT JOIN effective e ON s.simulate_id = e.simulate_id;

Yes, this is my SQL.
I can´t upload the analysis, but it is:

In QS:

Visual Key Performance Indicator (KPI) → field ‘total_customers’ in ‘Value’ → Aggregate (sum, average, count…)

When I aggregate the field “total_customers” (aggregate query), the sum value is stranger, and the count distinct always show 1.

When I put my analytical query in QS, it is OK, I mean, the aggregate sum is OK, the count distinct is OK.

Did you try to use the simple SQL as dataset?

Yes, when I use the plain SQL and it works. The problem is when I try to use the aggregated query. The value does not match.

Why dont use the plain one and aggregate in QS?

Because the simple SQL is 44 million per day

I just create a aggregate view with 500 rows and 3 distinct customers envolved, aggregate by date, product and category. When I try to visualize this field in Quick Sight, it returns 500 (if I aggregate by count) or 1 (if I aggregate by distinct count). I can’t visualize 3 value (customers)

Good Morning

Why does it happen, @ErikG ?

Thank you!

What do you mean by “this field”. What are you counting within the visual?
Can you create and share a table visiual with the columns

coupons,
simulates,
effective,
customers,
date,
category,
product

I have three different customers, but when all these fields are aggregated by distinct customer (count distinct idt_customer) the qty_customers
and I take this base to Quick Sight, I can’t visualize the value of 3 different customers. For example, in a bar chart, if I add this field “qty_customers”, by sum, the value returns is the same number of rows as the base, if I add it by count distinct, the value gives 1, that is, I don’t I can see the value 3 for the different customer.

Hi @July,
what if you are doing something like


BR

My count_distinct is 1.
Please could you share how you wrote your SQL?

Hello @July and @ErikG !

@July are you still having trouble with this or were you able to find a solution? If so could you share your solution to help the community?

@ErikG could you share the SQL you wrote that was mentioned above?

Hi @July
I didnt used SQL just the QS aggregation function within the KPI visual.
BR

2 Likes

I couldn’t use the aggregate SQL, I needed to use analytical query.

1 Like