Spotfire Text to Integer for Dates - date

I am attempting to load time series data from an excel spreadsheet into spotfire. In my spreadsheet there is a separate column for year (spotfire sees it as an integer) and month (spotfire sees it as text) since it is in the three letter abbreviation format ie January is JAN. I am trying to avoid changing the data in excel and would like to do all of my work in spotfire as this will be updated periodically. How do I link these columns in spotfire so that I can plot a variable over a time frame?

Click Insert > Insert Calculated Column... Make sure you have the right data table selected. In the Expression field type:
Date([year],
case when [month]="JAN" then 1
when [month]="FEB" then 2
when [month]="MAR" then 3
when [month]="APR" then 4
when [month]="MAY" then 5
when [month]="JUN" then 6
when [month]="JUL" then 7
when [month]="AUG" then 8
when [month]="SEP" then 9
when [month]="OCT" then 10
when [month]="NOV" then 11
when [month]="DEC" then 12 end,
1)
I would name it something like "monthdate". Note that each date will have the day equal to 1. If you also have the day in your data, just put that column in the formula above instead of the last 1.

Related

How to merge two data streams in Alteryx

Alteryx
Table 1 is a google sheet file. It has x fields with primary key.
Every day to that table is added the weekday with the x data
For example:
Monday
Tuesday (is added on Tuesday) and so on.
My problem is that my workflow has a formula that does calculations with all the Weekdays.
Example:
Balance = All_Income - Monday - Tuesday - Wednesday - Thursday - Friday - Saturday - Sunday
But today for example, in the google sheet data I don't have the other weekdays except Monday and Tuesday, so I get the error "Unknown Variable" for Thursday.
I've inserted a Text Input and added all the weekdays.
I want to (Append maybe) these two data streams together so that I have all the weekdays there.
So if I run the calculations I have all the weekdays there.
Right now that formula works only on Sunday, when all weekdays are inserted as columns.
Any idea how to achieve this?
(p.s Creating the weekdays as columns in the google sheet with empty rows is not an option).
I managed to do it by creating a Text Input with the same column names (headers) as the other Data Source and performing a union.
Apparently I needed to perform a IF statement to check all Weekdays if they exist and replace the null values with.
If anyone encounters the same error, feel free to contact for help :)
Use the Transpose tool to verticalise the days of the week. Then Summarize using the primary key and sum the [value] field. That will give you the balance regardless of which days of the week are present in your worksheet. This technique applies to any problem in which one needs to aggregate multiple fields which may or may not be present or known.
Here is the simplest path to victory:
1. Input worksheet.
2. Connect Transpose tool.
3. In Transpose Key Columns, select only primary key.
4. In Transpose Data Columns, deselect all fields except for days of week and Dynamic or Unknown Columns. This will still work even if the worksheet doesn't have all the days of the week because as they come in, the Dynamic or Unknown Columns option will select them as Data columns.
5. In Transpose Missing Columns, select Ignore.
6. Connect Summarize tool.
7. In Summarize, group by primary key and sum on [Value] field.
From here, you can rename the sum_value field to Balance or something else friendly. You can also use a Join tool, joining on primary keys, to the original worksheet to get back to where you started with the new aggregated value.

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:

Managing dates in SPSS - Time difference in months

Im a novice SPSS user and are working on a data set with two columns, customer ID and order date. I want to create a third variable with a month integer of number of inactive months since the observed customer ID:s last order date. This is how the data looks like:
This will create some sample data to demonstrate on:
data list list/ID (f3) OrderDate (adate10).
begin data
1 09/18/2016
1 03/02/2017
1 05/12/2017
2 06/06/2016
2 09/09/2017
end data.
Now you can run the following syntax to create a variable that contains the number of complete months between the date in the present row and the date in the previous row:
sort cases by ID OrderDate.
if ID=lag(ID) MonthSince=DATEDIF(OrderDate, lag(OrderDate), "months").

Last 7 days data calculation in Tableau

I am having an issue in calculating last week data in Tableau. Below is my scenario:
In my dashboard, I have a slider which selects the date. In my table, I have a list of users where I will be showing each of them's call records. One column will have last week records and one will have total records.
For Total records, there is not an issue. But for finding last week's count, I need to have a calculated field, that needs to subtract 7 days from the date selected and then give out the number of records for each user.
Say I have selected date as 25-04-2017, then my table should show all the records until 25-04-2017 in one column and other should show data from 18-04-2017 till 25-04-2017.
You can filter it with Relative days. When adding your dimension (date type) to the Filters list the picture below will appear.
Now you can click on the relative date and to choose the best option for you. You can see it in the picture below.
Create a Date parameter for your user to select. Using the Superstore data set, I created a calc field for last 7 days sales:
if datediff('day',[Order Date],[date]) <= 7 and datediff('day',[Order Date],[date]) >= 0 then [Sales] end
And sales up to date:
if datediff('day',[Order Date],[date]) >= 0
then [Sales] end
See attached example: https://www.dropbox.com/s/nqdp9zj74jay72d/170427%20stack%20question.twbx?dl=0
I was able to find the solution for my issue.
I created a boolean field as Max7Days with the formula as below:
DATEDIFF('day', [Date] , {MAX([Date])} ) <= 7
And created another that would count the number of records for the last 7 days if the condition was true as per the below formula:
CASE [Max7Days]
WHEN TRUE
THEN
[Number of Records]
END

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