问题
i have a table like this
order_id | user_id | createdAt | transaction_amount
order_id as the id of the transaction, user_id as the user, createdAt as the dates, and transaction_amount is the transaction of each id order.
so on tableau i want to find out users in time range '2020-01-01' until '2020-01-31' with 2 conditions
- the users are doing transaction before last date in range ('2020-01-31') and atleast doing more than 1 transaction
- and the users are at least doing 1 transaction in date range ('2020-01-01' until '2020-01-31')
on mysql that conditions can be described with this query
HAVING SUM(createdAt <= '2020-01-31') > 1
AND SUM(createdAt BETWEEN '2020-01-01' AND '2020-01-31')
on tableau i did this
[![enter image description here][1]][1]
on first filter (createdAt) i made range of dates ('2020-01-01' until '2020-01-31') on second filter (createdAt copy) i made range before last range ( < '2020-01-31') on filter CNTD(user_id) i made count distinct at least 1.
so it appear 2223 users, instead when i check it in mysql, its appear 1801 user, and the mysql was always right since i used mysql and im new in tableau. so what did i missed in here?
回答1:
Edit: Take this example
- user1 doing 2 transactions, 1 each in Dec-19 and Jan-20
- user2 doing 1 transaction in Jan-20
- user3 doing 2 transactions in Dec-19
- user4 doing 2 transactions in Feb-20
- user5 doing 2 transactions in Jan-20
data snapshot
Now if your date range is Jan-20 (say). If you want users doing at least two transactions before end of date range (31 Jan 2020) and at least one of these should be in Jan-2020 then user1 and user5 satisfy the condition.
In this case proceed like this-
Step-1 Create two date type
parameters (parameter 1
and parameter 2
respectively for start and end of date ranges)
Step-2 create a calculated field condition
with calculation as
{Fixed [User]: sum(
if [Trans Date]<=[Parameter 2] then 1 else 0 end)}>=2
AND
{FIXED [User]: sum(
IF [Trans Date]<=[Parameter 2] AND
[Trans Date] >= [Parameter 1] THEN 1 ELSE 0 END)}>=1
this will evaluate to TRUE
whenever your given condition is satisfied. See this screenshot.
Needless to say trans date is your createdAt
来源:https://stackoverflow.com/questions/64712691/how-to-find-out-users-id-with-some-conditions-filter