Tableau moving average - tableau-api

I have to count distinct users who log everyday to define whether they are active or not. One user is considered "active" if they logged in at least once in last 14 days.
Given a day X, my metric is calculating the % of distinct active users on the total registered.
So: % Active on day X = (#distinct users having logged at least once during the period X to X-13) / (total registered users on day X).
I can manually calculate it for day X.
What I find challenging is creating a time series of this metric (everyday one %, everyday a rolling period of 14 days).
So:
% Active on day X = (#distinct users having logged at least once during the period X to X-13) / (total registered users on day X),
% Active on day X-1 = (#distinct users having logged at least once during the period X-1 to X-14) / (total registered users on day X-1),
% Active on day X-2 = (#distinct users having logged at least once during the period X-2 to X-15) / (total registered users on day X-2),
etc.
useful information: I have a column containing the UserID, one containing every day he logged id (in case of multiple daily logs, still one row per day) and one column for the registration date.

Related

How do i group a table on a client and retreive the first admit in current year without having a null in prior discharge dates?

I have a table that contains client information with Episodes of treatment, admissions and discharges for each separate episode of treatment.
Client Episode Admission_date Discharge_date
x 1 05-06-2020 Null
x 2 09-26-2020 12-30-2020
x 3 01-03-2021 In Process
y 1 03-02-2020 05-20-2020
y 2 08-13-2020 11-23-2020
y 3 02-01-2021 03-31-2021
y 4 04-02-2021 In Process
I want to retrieve clients Y Episode 3(just retrieve the client no need episode) because its the first admission in year 2021 1st Qtr and their previous discharge date is less than(has to be less) Episode 3's admission date. But i dont want to retreive x even though their current admission date is less than previous discharge date because their first episode has a null in discharge which means they are still active. Need inactive clients only.
Would appreciate any help. Thank you
Desired result:
Client Episode Admission_date Discharge_date
y 3 02-01-2021 03-31-2021

How to count active users daily, weekly and monthly per month Tableau

I am currently trying to count how many distinct users are active:
At least once a day
At least once a week
At least once a month
per month, for every month in the year.
Ideally the output will be like this chart that is attached
What I have done so far is following this instructions "13. User login frequency" (https://www.tableau.com/about/blog/LOD-expressions).
This example is not what I am looking for because this calculates an average in all the months of the year and I need to calculate per month how many users are active at least once a day, how many users are active at least once a week and how many users are active ar least once a month.
Thank you very much

SAS start and end date from consecutive run

I have a dataset of customers buying items in multiple batches of consecutive days over the year e.g. Customer A buys on the 1st of January, the 2nd of January and the 3rd of January, stops, then buys again on the 1st of February, the 2nd of February and the 3rd of February.
I'm looking to capture the first and last date of each consecutive batch for each customer (so the usual MIN / MAX will miss out of batches in between dates).
I've experimented with RETAIN and LAG and I'm getting close but its not quite what I want.
How do I create a query that will display two rows for Customer A? i.e. row 1 showing start date of the 1st of January and end date of the 3rd of January; row 2 showing start date of the 1st of February and end date of the 3rd of February.
You are asking to group the values based on the presence of a gap between the dates. So test for that and create a new group number variable. Then you can use that new grouping variable in your analysis.
data want ;
set have ;
by id date;
dif_days = dif(sales_date);
if first.id then group=1;
else if dif_days > 1 then group+1;
run;
You can adjust the number of days in the last IF statement to adjust how large of a gap you want to allow and still consider the events as part of the same group.

Active redshift user count for specific time period

I need Active redshift user count for specific time period (say 20th Apr to 25th May).
I know PG_user table, but know luck with what i am looking for.
All on all i need a report with active user count for specific time period (20th Apr to 25th May).
Thanks a lot in advance.
Do you need to know how many user where logged in that time period?
to get the list day by day
select starttime, process, user_name
from stl_sessions where starttime>='2017-04-20' starttime <'2017-05-26'
to count users in total during that period:
select count(*)
from stl_sessions where starttime>='2017-04-20' starttime <'2017-05-26'

TABLEAU Calculating a Running DISTINCT COUNT on usernames for last 3 months

Issue:
Need to show RUNNING DISTINCT users per 3-month interval^^. (See goal table as reference). However, “COUNTD” does not help even after table calculation or “WINDOW_COUNT” or “WINDOW_SUM” function.
^^RUNNING DISTINCT user means DISTINCT users in a period of time (Jan - Mar, Feb – Apr, etc.). The COUNTD option only COUNT DISTINCT users in a window. This process should go over 3-month window to find the DISTINCT users.
Original Table
Date Username
1/1/2016 A
1/1/2016 B
1/2/2016 C
2/1/2016 A
2/1/2016 B
2/2/2016 B
3/1/2016 B
3/1/2016 C
3/2/2016 D
4/1/2016 A
4/1/2016 C
4/2/2016 D
4/3/2016 F
5/1/2016 D
5/2/2016 F
6/1/2016 D
6/2/2016 F
6/3/2016 G
6/4/2016 H
Goal Table
Tried Methods:
Step-by-step:
Tried to distribute the problem into steps, but due to columnar nature of tableau, I cannot successfully run COUNT or SUM (any aggregate command) on the LAST STEP of the solution.
STEP 0 Raw Data
This tables show the structure Data, as it is in the original table.
STEP 1 COUNT usernames by MONTH
The table show the count of users by month. You will notice because user B had 2 entries he is counted twice. In the next step we use DISTINCT COUNT to fix this issue.
STEP 2 DISTINCT COUNT by MONTH
Now we can see who all were present in a month, next step would be to see running DISTINCT COUNT by MONTH for 3 months
STEP 3 RUNNING DISTINCT COUNT for 3 months
Now we can see the SUM of DISTINCT COUNT of usernames for running 3 months. If you turn the MONTH INTERVAL to 1 from 3, you can see STEP 2 table.
LAST STEP Issue Step
GOAL: Need the GRAND TOTAL to be the SUM of MONTH column.
Request:
I want to calculate the SUM of '1' by MONTH. However, I am using WINDOW function and aggregating the data that gave me an Error.
WHAT I NEED
Jan Feb March April May Jun
3 3 4 5 5 6
WHAT I GOT
Jan Feb March April May Jun
1 1 1 1 1 1
My Output after tried methods: Attached twbx file. DISTINCT_count_running_v1
HELP taken:
https://community.tableau.com/thread/119179 ; Tried this method but stuck at last step
https://community.tableau.com/thread/122852 ; Used some parts of this solution
The way I approached the problem was identifying the minimum login date for each user and then using that date to count the distinct number of users. For example, I have data in this format. I created a calculated field called Min User Login Date as { FIXED [User]:MIN([Date])} and then did a CNTD(USER) on Min User Login Date to get the unique user count by date. If you want running total, then you can do quick table calculation on Running Total on CNTD(USER) field.
You need to put Month(date) and count(username) in the columns then you will get result what you expect.
See screen below