Add a new row in spotfire - visualization

I have a dataset and I want to analyze the shift wise performance.
For example:
Crew 2 made last connection is at 09-08-2017 05:00:00 and the shift ends at 09-08-2017 06:00:00
After a few minutes crew 1, whose shift starts at 09-08-2017 06:00:00, make a connection # 09-08-2017 06:03:00. But all the work for the latest connection was done by crew 2. I want to attribute that work to crew 2 instead of crew 1.
What I want to do is add two new rows, one just before 09-08-2017 06:00:00 and one just after 09-08-2017 06:00:00 to represent the work done by crew 2 and crew 1 respectively.
so for example, something like 09-08-2017 05:59:59 for crew 2 and 09-08-2017 06:01:00 for crew 1.
Please refer to the attached screenshot of the dataset. I need to add rows between column Id 1 and column Id 2.
enter image description here

Related

Calculate data with overlapping dates in SQL

I'm using PostgreSQL 13 (I can update to 14 if that helps) and I'd like to return some rows based on data I've got.
The data I've got is a bit complex and comes from a few different tables but I don't think it matters here.
Currently I was able to create a query that returns data that looks like this:
Product ID Start End AvailableAmount
------------ ------------- ------------- ------------------
1 null null 2
1 2022-07-20 2022-07-22 1
1 2022-07-24 2022-07-27 1
2 null null 1
3 null null 5
Where Start is the start of a time period, End is the end of the period, AvailableAmount is the amount of product available in that time period. Available amount is calculated based on some other data.
I've tried summing up the AvailableAmount column but that does not return valid data because for time period from 2022-07-20 to 2022-07-24 AvailableAmount should be 1 but it's 2.
I think I'd need to somehow separate these dates and list the amount per day, not per time period but I don't know how.
Basically, going day by day, AvailableAmount for product with ID 1 should be:
2022-07-20: 1
2022-07-21: 1,
2022-07-22: 1,
2022-07-23: 2,
2022-07-24: 1,
2022-07-25: 1,
2022-07-26: 1,
2022-07-27: 1,
2022-07-28: 2,
...
so if I'd to query for the product with time period 2022-07-20 to 2022-07-25 I should be able to request 1 unit of the product. Currently my implementation makes it impossible as it's summing up the amount so if my request spans over two different time periods the available amount is lower than it should be.
I've tried using gaps and islands approach but I don't think it'd work here. I've also read about multirange that was introduced in v14 but I haven't tested it yet, working on it. I've also tried using generate_series but that did not help me.
I don't know if that is enough information but I can provide more if needed.
Thanks!

Use one date filter on multiple columns in tableau

I do have data set with multiple date columns with different values of dates across all the months and years. I want to create a report wherein when I select a Year, I want to list the count of dates across each months on that year. Based on one Year field selection, how can I apply filter across different date fields to display the counts for that particular year
Lets say we have the data set like this
Date 1 Date 2
1/3/2017 NA
1/23/2017 1/23/2017
1/14/2017 1/16/2017
2/2/2017 2/3/2017
NA 2/21/2017
3/1/2017 NA
3/3/2017 3/21/2017
.
.
.
12/1/2017 12/12/2017
My result should look like this when I pick the year 2017
Date 1 Date 2
Jan 3 2
Feb 1 2
Mar 2 1
.
.
Dec 1 1
I was able to apply filter on one column but when I try to apply on other columns, I am not getting desired result
Assuming you want to interact with your dashboard using a parameter, you can create one string parameter in order to input the year you want to analyze.
After that you just need to create 2 calculated fields to count if that year is "contained" in your dates:
if contains(str([Date 1]),[Parameter]) then 1 else 0 end
Keep in mind that there's no gaurantee you'll get all the available months in the calendar unless you have data for all of them.
In order to consider even blank dates, I created a Date Global calculated field as follow:
ifnull([Date 1],[Date 2])
Once you've created this fields/parameter (show parameter control), you can simply add them in your worksheet ad I did in the image:

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

Formula to input data with reference to a date range

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))

Generating Running Sum of Ratings in SQL

I have a rating table. It boils down to:
rating_value created
+2 april 3rd
-5 april 20th
So, every time someone gets rated, I track that rating event in the database.
I want to generate a rating history/time graph where the rating is the sum of all ratings up to that point in time on a graph.
I.E. A person's rating on April 5th might be select sum(rating_value) from ratings where created <= april 5th
The only problem with this approach is I have to run this day by day across the interval I'm interested in. Is there some trick to generating a running total using this sort of data?
Otherwise, I'm thinking the best approach is to create a denormalized "rating history" table alongside the individual ratings.
If you have postgresql 8.4, you can use a window-aggregate function to calculate a running sum:
steve#steve#[local] =# select rating_value, created,
sum(rating_value) over(order by created)
from rating;
rating_value | created | sum
--------------+------------+-----
2 | 2010-04-03 | 2
-5 | 2010-04-20 | -3
(2 rows)
See http://www.postgresql.org/docs/current/static/sql-expressions.html#SYNTAX-WINDOW-FUNCTIONS
try to add a group by statement. that gives you the rating value for each day (in e.g. an array). as you output the rating value over time, you can just add the previous array elements together.