Previous Month Calculated Column in Tableau - calculated-columns

Been trying to find an easy way to calculate the previous month values. Not sure how to get it to work correctly.
This is what I did for Current Month:
IIF(DATETRUNC('month',[Approved for Hire Date]) = DATETRUNC('month',TODAY()),'true','false')
What I tried for Previous Month"
IIF(DATETRUNC('month',[Offer Accepted Date]) = DATETRUNC('month',-1,DATETRUNC('month',TODAY())),'true','false')

Related

How to find a trend/forecast result 14 days from today

I have looked into the Forcast & Trend formula but I cannot figure it out for the life of me.
I want to work out the trend 14 days from now.
I have a set of data:
A1 - A30 with dates
B1 - B30 with daily ticket count for the business.
I would like to make a result in another cell that would predict what the estimated total ticket count would be 14 days from now. I do not need all 14 days, just the 14th day.
If I was to try show you what the formula looks like in my head it would be:
=trend/forecast(B1:B30,14)
or
=Predict(B1:B30)*14
Unfortunately it is not as easy as that. How can I do this?
I think you want to use the Forecast function. The inputs you have do not match the correct format though.
FORECAST( x, known y's, known x's) where...
x = the series (or date) you want to forecast
known y's = historical tickets per day
known x's = historical dates (or series)
The below example allows you to forecast tickets for any date (Forecasted Date) given the historical information (table on left). If your table is not formatted with actual dates, just create a series (first day = 1, second day = 2, etc.) and forecast that way.
Given the historical data, the forecasted tickets for Aug 28th (14 days after last known value) are 16.7

Search for particular format of date in saved search

I'm trying to find the customers whose birthday is in next month and the way the birthdays of customers will be entered at the stores is, they just ask for day and month and put in the current year for year.
So, when I', trying to do the search as next month it seem like I can only search with in a range that include year, which don't work in this case.
I've tried the below with search field set to is february but it don't automate the search as I have to change the month every month
TO_CHAR({custentity_spos_date1},'MONTH, YYYY')
Does some one have any idea how to include only month in search so that I can search for customers who's birthday is in a particular month?
case
when to_char({today}, 'MM') = '12' then
case
when to_char({custentity_spos_date1}, 'MM') = '01' then 1
else 0
end
when to_number(to_char({custentity_spos_date1}, 'MM')) = to_number(to_char({today}, 'MM')) + 1 then 1
else 0
end
equal to 1
The filter basically says if the month of the current date is 12, then match any record where the month of the date field is 1, otherwise match any record where the month of the date field is equal to the month of the current date + 1.
There may be an easier way, but this worked for me.
You can use the SQL formatting and ADD_MONTHS functions to compare only the month component of the date:
CASE WHEN TO_CHAR({custentity_spos_date1}, 'MM') = TO_CHAR(ADD_MONTHS(sysdate, 1),'MM') THEN 1 ELSE 0 END
Equal to 1.

How do I get the Month End Personal Time Off Days used?

Using the Start Date and End Date of PTO - Personal Time Off Days Used only count days used up to end of prior month, excluding weekends and U.S Holidays in that certain month. Example of a Holiday is Sept 7th 2015 in the United States.
My goals are:
Create a Data Item Month End Personal Time Off Days used.
Of course it should be getting the number of PTO Days USED from the prior month only.
Exclude weekends in that certain month. So if the Resource takes a Leave on Friday and Monday, Saturday and Sunday should not be excluded in the computation.
How to exclude U.S Holidays, if this is possible that's great but if it's not possible then I'm okay with numbers 1, 2 and 3.
I have created a Data Item column that captures the PTO days used. But this is good for Year to date.
Case when [PTO Info].[PTO Audit].[PTOAuditTypeId] = 31571
and [PTO Info].[PTO Audit].[TimeOffTypeId] = 31566
then [PTO Info].[PTO Audit].[PTODays]
when [PTO Info].[PTO Audit].[PTOAuditTypeId]=31572
and [PTO Info].[PTO Audit].[TimeOffTypeId] = 31566
and [PTO Info].[PTO Audit].[PTODays] < 0
then abs([PTO Info].[PTO Audit].[PTODays] )
else 0 end
I'm not sure if the query below can help.
A calendar table is really going to help you out here. Assuming it has one record per calendar date, you can use this table to note weekends, holidays, fiscal periods vs Calendar periods, beginning of month/end of month dates. A number of things that can help simplify your date based queries.
See this question here for an example on creating a calendar table.
The main point is to create a data set with 1 record per date, with information about each date including Month, Day of Week, Holiday status, etc.
Without a calendar table, you can use database functions to generate your set of dates on the fly.
Getting the Month number for a date can be done with
extract([Month], <date field goes here> )
Getting a list of values from nothing will be required to generate your list of dates (if you don't have a calendar table with 1 record per date to use) will vary depending on your source database. In oracle I use a 'select from all_objects' type query to achieve this.
An example from Ask Tom:
select to_date(:start_date,'dd-mon-yyyy') + rownum -1
from all_objects
where rownum <=
to_date(:end_date,'dd-mon-yyyy')-to_date(:start_date,'dd-mon-yyyy')+1
For Sql Server refer to this stackoverflow question here.
Once you have a data set with your calendar type information, you can join it to your query above:
join mycalendar cal on cal.date >= c.PTOStartDate
and cal.date <= c.PTOEndDate
Also note, _add_days is a Cognos function. When building your source queries, try and use Native functions, like in oracle you can 'c.PTOStartDate + a.PTODays'. Mixing Cognos functions with native functions will sometime force parts of your queries to be processed locally on the Cognos server. Generally speaking, the more work that happens on the database, the faster your reports will run.
Once you have joined to the calendar data, you are going to have your records multiplied out so that you have 1 record per date. (You would not want to be doing any summary math on PTODays here, as it will be inflated.)
Now you can add clauses to track your rules.
where cal.Day_Of_Week between 2 and 6
and cal.Is_Holiday = 'N'
Now if you are pulling a specific month, you can add that to the criteria:
and cal.CalendarPeriod = '201508'
Or if you are covering a longer period, but wanting to report a summary per month, you can group by month.
Final query could look something like this:
select c.UserID, cal.CalendarPeriod, count(*) PTO_Days
from dbo.PTOCalendar c
join myCalendar cal on on cal.date >= c.PTOStartDate
and cal.date <= c.PTOEndDate
where cal.day_of_week between 2 and 6
and cal.Is_Holiday = 'N'
group by c.UserID, cal.CalendarPeriod
So if employee with UserID 1234 Took a 7 day vacation from thursday June 25th to Friday July 3th, that covered 9 days, the result you get here will be:
1234 201506 4
1234 201507 3
You can join these results to your final query above to track days off per month.

Change the date to fiscal year

I want to write a function in Excel to change the date. The logic is like this: if the month is (Jan, Feb or March) the result show me one year past (-1 year) and if the month is (April to -December) the result show the current year (which year the date shows).
example: if date is 02,Jan,2012 the result show me 2011 else show me 2012.
=IF(MONTH(G3) >=4, YEAR(G3), YEAR(G3) - 1) where G3 is the date to test, is one way.
Please try:
=IF(OR(MONTH(A1)=1,MONTH(A1)=2,MONTH(A1)=3),2011,2012)
With 02-Jan-2012 in A1 try,
=YEAR(A1)-(MONTH(A1)<4)
For a full date use one of these,
=DATE(YEAR(A1)-(MONTH(A1)<4), MONTH(A1), DAY(A1))
=EDATE(A1, -(MONTH(A1)<4)*12)
To extract fiscal year use:
=YEAR(A1) + IF(MONTH(A1)>=4,1,0)
I think in your case you would need:
=YEAR(A1) - IF(MONTH(A1)>=4,0,1)
If the months is before 4th month then subtract 1 year, else keep the same year. I wouldn't convert it to a full date DD/MM/YYYY with a 1 year subtracted, to avoid confusion keep it as year only YYYY.
Already plenty of answers, but thought I'd throw another one up:
=YEAR(DATE(YEAR(A1),MONTH(A1)-3,DAY(A1)))

Using Workday when start date is a wekeend date

I have a spreadhseet that pulls Planned Maintenace due dates. I am calculating 5 potential days the work can be scheduled, from 2 days before to days days after, so a range of 5 days. Unfortunately, sometimes the original due date is a weekend date(our business system calculates but doesn't append for weekend dates). So when I calculate the first 2 days, =workdate(A1,-2,holiday) and =workdate(A1,-1,holiday)it works fine, however for the 3rd date =workdate(A1,0,holiday) returns the original due date even if it's a weekend date.
Example, July 6th 2013 is a Saturday, so
1. workdate(A1,-2,holiday) = 7/3/2013
2. workdate(A1,-1,holiday) = 7/5/2013
3. workdate(A1,0,holiday) = 7/6/2013 needs to be 7/8/2013
4. workdate(A1,1,holiday) = 7/8/2013 needs to be 7/9/2013
5. workdate(A1,2,holiday) = 7/9/2013 needs to be 7/10/2013
Is there any way to compensate for a start date that is a weekend date!
Thanks in advance for any help or suggestions.
The function it appears you are using is workday(), not workdate()? So what you probably need to do is put an adjustment on the # you pass to Workday if the day of the week is Sat/Sun.
=WORKDAY(A1,IF(OR(TEXT(A1,"ddd") = "Sat",TEXT(A1,"ddd") = "Sun"),1,0))
=WORKDAY(A1,IF(OR(TEXT(A1,"ddd") = "Sat",TEXT(A1,"ddd") = "Sun"),2,1))
=WORKDAY(A1,IF(OR(TEXT(A1,"ddd") = "Sat",TEXT(A1,"ddd") = "Sun"),3,2))

Resources