Search for particular format of date in saved search - netsuite

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.

Related

NetSuite Saved Search Formula for This Week

I am trying to create a saved search that shows total orders today, yesterday, this week and this month. I am able to get all but the weekly one using date formulas.
All are Formula(Numberic) fields with summary type Count.
Today: CASE WHEN {trandate} = to_date({today}) THEN {number} END
Yesterday: CASE WHEN {trandate} = to_date(({today} - 1)) THEN {number} END
This Week??
This Month: CASE WHEN {trandate} BETWEEN to_date(TRUNC({today}, 'MONTH'), 'MM/DD/YYYY') AND to_date(LAST_DAY{today}) THEN {number} ELSE 0 END
Any suggestions appreciated!
The way to get this depends on whether you want values for the last 7 days or for this calendar week.
For the last 7 days:
case when {now} - {trandate} < 7 then {number} else 0 end
or for the current week
case when to_char({now}, 'IW') = to_char({trandate}, 'IW') then {number} else 0 end
where 'IW' is for the ISO Standard week numbering. You can also use 'WW' for week numbering where week 1 starts on Jan 1, week 2 on Jan 8 etc.
I'd suggest calculating the day of the week and using that to work back to the start of the week.
I have not tested, but my understanding is that Oracle db functions should work.
to_date({today} - to_char({trandate}, 'D'))
https://livesql.oracle.com/apex/livesql/file/content_GCEY1DN2CN5HZCUQFHVUYQD3G.html

Select records with at one day in centain year

I want to make a selection of records where date range (start date - end date) includes at least 1 day of 2020. So for example: if a record has 2018-01-13 as the start date and 2020-01-09 as end date, it has to be included in my selection, as there is at least one day active in 2020.
Sample data:
How can I achieve this?
Just check the years with the standard between notation
Start Year <= 2020 <= End Year
=AND(YEAR(A1)<=2020,YEAR(B1)>=2020)
=IF(OR(YEAR(A2)=2020,YEAR(B2)=2020),1,0)
Excel store dates as numbers, so, you must compare them like numbers
Make a column with: =IF(OR(B2 < $C$2; $D$2 < A2); 0; 1)
where
A: start date
B: final date
C: 2020-01-01
D: 2020-12-31
, Now you can use only values 1

Calculated Column that counts from 1-53 per week from specific start date

I am facing a relatively trivial problem. I have a list of start dates for each fiscal year. For example, 03.01.2019 for the 2019 financial year or 30.12.2019 for the 2020 financial year.
Now I want the calculated column in my calendar table (Power Pivot) to count up from the start date from 1-53 per week until the next start date.
It would look like this:
03.01.2019 - 1
04.01.2019 - 1 ....
Does anyone know how to do this?
You cen get the ISO 8601 weeknumbers by adding 21 in the optional part. Here a quick example I created. But if you also have dates which start in the middle of the year you should go with a calendar, like #Kosuke Sakai posted:
Generally, the recommended approach for this requirement is to prepare a fiscal calendar in the data source (DWH, MDM, Excel, or somewhere), rather than to calculate with DAX.
Having said that, it is possible with DAX.
Assuming you have a table like below. (Let's call it FiscalYears)
First, you need to add FiscalYear calculated column to your Calendar table with following formula.
FiscalYear :=
VAR CurrentDate = [Date]
RETURN CALCULATE (
MAX ( FiscalYears[FiscalYear] ),
FiscalYears[StartDate] <= CurrentDate
)
Then, you can use this to calculate WeekNumberInFiscalYear column.
WeekNumberInFiscalYear :=
VAR StartDate = LOOKUPVALUE (
FiscalYears[StartDate],
FiscalYears[FiscalYear],
[FiscalYear]
)
RETURN DATEDIFF ( StartDate, [Date], WEEK ) + 1
The result will be looking like below.

Retutn only Buisness days in custom date function in excel

I have a date which I will need to increment the date by a day, month or year from the actual date. This is based of a list of fields below and is different per the input. Also each resultant date has to be a business day i.e not a weekend day or a bank holiday. Also if the resultant date is either Dec 25 or Jan 1st the day needs to move forward to the next business day (not a weekend day).
I have created this in Excel using a couple of formulas though it is a bit clunky.
Below is my data set
Business Date 15/05/2018
Tenor Settlement Value Settlement Period
ON 1 Day
TN 2 Day
SP 2 Day
SN 3 Day
1W 7 Day
2W 14 Day
3W 21 Day
1M 1 Month
2M 2 Month
3M 3 Month
In column E - I am using formula
=IF(D4="Day",$B$1+C4,IF(D4="Month",EDATE($B$1,C4),(TEXT($B$1,"dd/mm/")&(YEAR($B$1)+C4))+0))
In column F - I am using formula
=E4+LOOKUP(WEEKDAY(E4),{1,2,3,4,5,6,7},{1,0,0,0,0,0,2})
In column G - I am using formula
=F4+IF(AND(OR(TEXT(F4,"ddmm")="2512",TEXT(F4,"ddmm")="0101"),WEEKDAY(F4)>=2,WEEKDAY(F4)<=6),LOOKUP(WEEKDAY(F4),{1,2,3,4,5,6,7},{0,1,1,1,1,3,0}),LOOKUP(WEEKDAY(F4),{1,2,3,4,5,6,7},{1,0,0,0,0,0,2}))
In H I format the date in mm/dd/yyyy and I have my desired result.
storax has kindly created a function for me which replicates my excel formula in column E - on this thread Increment a date by a number of days, months or years
Function IncDate(ByVal dt As Date, ByVal add As Long, ByVal dmy As String) As Date
Select Case UCase(dmy)
Case "DAY"
IncDate = DateAdd("d", add, dt)
Case "MONTH"
IncDate = DateAdd("m", add, dt)
Case "YEAR"
IncDate = DateAdd("yyyy", add, dt)
Case Else
IncDate = dt
End Select
Could use some advise on how I could incorporate my formulas in columns F & G to make the process less clunky.
Manipulating the DATE function (DateSerial in vba) with the WORKDAY.INTL function seems to produce the correct business dates.
Put this in E4 and fill down.
=WORKDAY.INTL(DATE(YEAR(B$1)+(D4="year")*C4, MONTH(B$1)+(D4="month")*C4, DAY(B$1)+(D4="day")*C4)-1, 1, 1, holidays)
[holidays] is a named range (Formulas, Defined Names, Defined Name) with a Refers To: of,
=Sheet10!$Z$2:INDEX(Sheet10!$Z:$Z, MATCH(1E+99, Sheet10!$Z:$Z))

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.

Resources