I have an issue where the following query
WITH SumByUid AS (
SELECT
Uid,
SUM(Value) AS TotalValue
FROM
your_table
WHERE day between '2023-08-01' and '2023-08-15'
GROUP BY
Uid
)
SELECT
COUNT(*) AS UserCountUnderThreshold
FROM
SumByUid
WHERE
TotalValue < 600000;
Returns a value of = 40k+
But comparing on tableau with the formulars below returned 89K+ After filtering by date within the specified date range i.e '2023-08-01' and '2023-08-15'
TotalValueUser = { FIXED [User Id] : sum([Value])}
ActiveUsers = if [TotalValuebyUser] > 600000 THEN 'YES' ELSE 'NO' END
TotalValue column was being aggregated twice; once in your query, and then again in Tableau causing the discrepancy.