I just started to use Tableau and I would like to know how to take the latest value available.
For example I have :
ID Date Active
1 01/01/2016 1
1 01/02/2016 1
1 01/07/2016 0
2 01/02/2016 1
2 01/08/2016 0
Now I would like to have a view by month on the SUM of the Active flag, something like :
01/01/2016 1
01/02/2016 2
01/03/2016 2
01/04/2016 2
01/04/2016 2
01/05/2016 2
01/06/2016 2
01/07/2016 1
01/08/2016 0
As you can see we assume that the Active flag take the latest value available like :
1 01/01/2016 1
1 01/02/2016 1
1 01/07/2016 0
Will be transform in :
01/01/2016 1
01/02/2016 1
01/03/2016 1
01/04/2016 1
01/04/2016 1
01/05/2016 1
01/06/2016 1
01/07/2016 0
After you do the sum on the Active flag.
I think that I have to use Calculated field but I didn't manage t find the right formula.
I assume your example contains an error so I give you the solution for the problem as I understand it. Please explain how I misinterpreted. I do feel like the techniques used should apply nevertheless.
I think you want two things: first you want Tableau to show missing months, which you can do by right clicking on the months and selecting show missing values. This would give you:
Month of Date Active
January 1
February 2
March
April
May
June
July 0
August 0
Secondly you would like missing values to have the value of the result of the previous month.
Month of Date Active
January 1
February 2
March 2
April 2
May 2
June 2
July 0
August 0
And here I have a difference from your example since you state July should have a value of 1 which I don't understand since the sum of July is 0.
If it is the case that this is just due to a typo you can achieve the above table by indeed using a calculated field:
ifnull(sum([Active]), previous_value(0))
If I misinterpreted some part of your problem, please let me know so I change my solution accordingly. But I think in general a combination of lookup, ifnull and previous_value will be able to solve your issue.
Related
i have a table with detail transaction for lot. Lot are harvest and store before being ship.
Date lot transaction qty
5 sept 3 store 300
8 sept 3 ship -50
10 oct 3 ship -20
15 nov 3 ship -20
...
If i want the inventory for a specific moment, i simply sum between to date
I would like a query that can give me a sum from store to a specific month throught the entirr year like:
Lot sept to oct to nov ...
3 250 230 210 ...
Select lot, sum(qty) from ... where (date > 1 sept and date < 1 oct) as sept, (date > 1 sept and date < 1 nov)... group by lot
I did'nt find anything or figure out how to do it i a simple query.
Regards
Obtain one table with a query where is see the evolution of quantity over the year.
I have data with 2 columns, in the following format:
ID
Date
1
1/1/2020
1
27/7/2020
1
15/3/2021
2
18/1/2020
3
1/1/2020
3
3/8/2020
3
18/9/2021
2
23/8/2020
2
30/2/2021
Now I would like to create a calculation field in Tableau to find per ID the difference between the different dates. For any value e.g. days.
For example for ID 1 the difference of the two dates according to calendar is 208 days. Next the difference of the second to third date for the same ID is 231 days.
A table calc like the following should do if you get the partitioning, addressing and ordering right — such as setting “compute using” to Date.
If first() < 0 then min([Date]) - lookup(min([Date]), -1) end
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
I am encountering different results while using AGE function in postgresql 9.1.
Incorrect. Two days are added when the current day is changed from Feb 28 to March 1st.
Query : select AGE ('2015-02-28', '2012-06-24');
Result : 2 years 8 mons 4 days
Query : select AGE ('2015-03-01', '2012-06-24');
Result : 2 years 8 mons 7 days
Seems correct, when the age is computed from 2014-02-27. The extra days are not added here.
Query : select AGE ('2015-02-28', '2014-02-27');
Result : 1 year 1 day
Query : select AGE ('2015-03-01', '2014-02-27');
Result : 1 year 2 days
What must be happening while the query is being run?
The documentation says:
PostgreSQL's approach uses the month from the earlier of the two dates when calculating partial months. For example, age('2004-06-01', '2004-04-30') uses April to yield 1 mon 1 day, while using May would yield 1 mon 2 days because May has 31 days, while April has only 30.
So for your example, the 2012-06-24is your "earlier date" and the june has 30 days. So your difference computes as 24 to 30 is 6 and to 1 is 7.
This is not sane imho, but the age() function behaves exactly how it should according to the documentation.
Edit:
To be more precise: the age() function does not compute differences between dates. Don't use it to do that.
Currently I am trying to come up with a leave tracking system using OpenOffice Calc, so I have two sheets of data:
sheet 1:
s/n name date start date end
1 test 3 Jan 2012 3 Jan 2012 <- formatted to date format
2 test 6 Jan 2012 8 Jan 2012
while sheet 2 should look like this after I add in the formula:
name 3Jan 4Jan 5Jan 6Jan 7Jan 8Jan <- formatted to date format
test 1 1 1 1
My problem is how to use a formula on the second sheet under the dates which would refer to sheet 1 and automatically add a 1 if the person is on leave on that day. The dates will give me a serial number if I were to get the value from the cell which I use to match the dates on sheet 1 and sheet 2.
Using VLOOKUP I was able to get the value of the date start and end in sheet 1 from sheet 2:
=VLOOKUP(A2;$A$2:$D$3;3;0)
=VLOOKUP(A2;$A$2:$D$3;4;0)
and then an IF statement to add a 1 or a "":
=IF(VLOOKUP(A2;$A$2:$D$3;3;0)=MID(B1;1;6);"1";"")
However I face a problem with this part with a leave of many days (example entry 2 in sheet 1 where the leave ranges from 6 - 8 Jan).
So I tried to compare the values if the date is greater than or equal to the start date and the date is less than or equal to the end date, but failed. This is the formula I tried:
=IF(VLOOKUP(A2;$A$2:$D$3;3;0)>=MID(B1;1;6)<=VLOOKUP(A2;$A$2:$D$3;4;0);"1";"")
Can anyone can help me with this issue or have any better ideas?
Assuming s/n is in A1 of your !st sheet and Name in A1 of your second sheet, in B2 of your second sheet and copied across to suit:
=IF(COUNTIFS(first.$B1:$B99;$A2;first.$C1:$C99;"<="&B$1;first.$D1:$D99;">="&B$1)=0;"";COUNTIFS(first.$B1:$B99;$A2;first.$C1:$C99;"<="&B$1;first.$D1:$D99;">="&B$1))