NetSuite Saved Search to Compare YOY sales to the end of last month - netsuite

Trying to create a saved search that will display last years sales to the end of last month, and this years sales to the end of last month in two separate colmns using forumals.
I'm able to pull the sales for ALL of last year and ALL of this year using the formulas below:
-- 2021 Sales --
(CASE WHEN TO_CHAR({TODAY},'YYYY')-1=TO_CHAR({shipdate},'YYYY')
AND {type} = 'Invoice' THEN {AMOUNT}
ELSE 0 END)+
(CASE WHEN TO_CHAR({TODAY},'YYYY')-1=TO_CHAR({shipdate},'YYYY')
AND {type} = 'Sales Order' THEN {AMOUNT}
ELSE 0 END)+
(CASE WHEN TO_CHAR({TODAY},'YYYY')-1=TO_CHAR({trandate},'YYYY')
AND {type} = 'Return Authorization' THEN {AMOUNT}
ELSE 0 END)+
(CASE WHEN TO_CHAR({TODAY},'YYYY')-1=TO_CHAR({trandate},'YYYY')
AND {type} = 'Credit Memo' THEN {AMOUNT}
ELSE 0 END)
-- 2022 Sales --
(CASE WHEN TO_CHAR({TODAY},'YYYY')=TO_CHAR({shipdate},'YYYY')
AND {type} = 'Invoice' THEN {AMOUNT}
ELSE 0 END)+
(CASE WHEN TO_CHAR({TODAY},'YYYY')=TO_CHAR({shipdate},'YYYY')
AND {type} = 'Sales Order' THEN {AMOUNT}
ELSE 0 END)+
(CASE WHEN TO_CHAR({TODAY},'YYYY')=TO_CHAR({trandate},'YYYY')
AND {type} = 'Return Authorization' THEN {AMOUNT}
ELSE 0 END)+
(CASE WHEN TO_CHAR({TODAY},'YYYY')=TO_CHAR({trandate},'YYYY')
AND {type} = 'Credit Memo' THEN {AMOUNT}
ELSE 0 END)
I tried to re-structure it to only show sales for both years through the end of last month (or last month for the previous year) but I keep getting an invalid expression:
(CASE WHEN {type} = 'Invoice'
THEN (CASE WHEN {shipdate}
BETWEEN TO_DATE({TODAY},'YYYY')=TO_CHAR({shipdate},'YYYY')
AND TO_CHAR({TODAY},'MM')-1=TO_CHAR({shipdate},'MM')
THEN {AMOUNT}
ELSE 0 END)
ELSE 0 END)+
(CASE WHEN {type} = 'Sales Order'
THEN (CASE WHEN {shipdate}
BETWEEN TO_DATE({TODAY},'YYYY')=TO_DATE({shipdate},'YYYY')
AND TO_DATE({TODAY},'MM')-1=TO_DATE({shipdate},'MM')
THEN {AMOUNT}
ELSE 0 END)
ELSE 0 END)

In the BETWEEN condition, all expressions must evaluate to numeric, character or datetime values - in this case datetime. Where you have
BETWEEN TO_DATE({TODAY},'YYYY')=TO_CHAR({shipdate},'YYYY')
AND TO_CHAR({TODAY},'MM')-1=TO_CHAR({shipdate},'MM')
the results of TO_DATE({TODAY},'YYYY')=TO_CHAR({shipdate},'YYYY') for example will evaluate to a boolean. So it's like you're saying "If this date is between true and false" which makes no sense. Try this instead for this year:
CASE WHEN {type} = 'Invoice' THEN (
CASE WHEN {shipdate} BETWEEN LAST_DAY(
ADD_MONTHS(
sysdate,
TO_CHAR(sysdate, 'MM')*-1
)
) + 1
AND LAST_DAY(
ADD_MONTHS(sysdate, -1)
) THEN {amount} ELSE 0 END
) END
And for last year:
CASE WHEN {type} = 'Invoice' THEN (
CASE WHEN {shipdate} BETWEEN LAST_DAY(
ADD_MONTHS(
sysdate,
(
TO_CHAR(sysdate, 'MM')+ 12
)*-1
)
) + 1
AND LAST_DAY(
ADD_MONTHS(sysdate, -13)
) THEN {amount} ELSE 0 END
) END

Related

Calculate Days Between Dates excluding Sundays

Would anyone be able to help me calculate the number of days between two dates excluding Sundays in Cognos? I would also like to count the next day as the first counted day. For example, if something was picked up on a Monday, the first counted day would be Tuesday.
I was using this logic however it is not what I need
1 + 5 * (_days_between (cast([Finish] as date);cast([Start] as date))
-_day_of_week (cast([Finish] as date);1)+_day_of_week (cast([Start] as date);1))/7
if (_day_of_week (cast([Start] as date);1) > 5) then (6) else (_day_of_week (cast([Start] as date);1))
if (_day_of_week (cast([Finish] as date);1) > 5) then (5) else (_day_of_week (cast([Finish] as date);1))
If the database column with the dates is continuous, meaning it is not missing any date records you could try:
total(if ((_day_of_week ([Introduction date],1<>7 ) and( [Introduction date] between _add_days(?startDate?,1) and ?EndDate?))
then
(1)
else
(0))

Blank Cell equal to value Zero in another cell should returns True in python,pandas

Below is my data in excel format
Where there is a blank cell it is treating as general
Where there are amounts, format is "#,##0.00000;(#,##0.00000)"
I have written the below code to calculate the Blank cell equal to value zero from another cell should return True
import pandas as pd
df=pd.read_excel('Book1.xlsx',dtype=str)
df.replace('nan','',inplace=True)
df['True']=''
df.loc[df['Amount_1'] == df['Amount_2'],'True'] = 'True'
df.loc[df['Amount_1'] != df['Amount_2'],'True'] = 'False'
df
Name Amount_1 Amount_2 True
0 A1 0 False
1 A2 0 False
2 A3 0.01 False
If I am doing it in excel I am getting True for the first two rows whereas I am getting False here.
My End Result/Expected Result should be:
True for A1 and A2 but I am getting False instead.
While writing to Excel blank cells should come as blanks.
You could give more conditions such as
import pandas as pd
df=pd.read_csv('test.csv',dtype=str) # this is modified for my test.
df=df.fillna('')
df['True'] = ''
df.loc[df['Amount_1'] != df['Amount_2'], 'True'] = 'False'
df.loc[df['Amount_1'] == df['Amount_2'], 'True'] = 'True'
df.loc[(df['Amount_1'] == '') & (df['Amount_2'] == '0'), 'True'] = 'True'
df.loc[(df['Amount_2'] == '') & (df['Amount_1'] == '0'), 'True'] = 'True'
df
where the result is:
Name Amount_1 Amount_2 True
0 A1 0 True
1 A2 0 True
2 A3 0.01 False

Combine work days and calendar days for a calculator

Im trying to create a calculator for detention of containers.
Each provider has different rules that have a breakdown between work days and calendar days.
for example:
the first 5 working days (excl Saturday and Sunday) are free of cost
After that the next 3 calendar days are at a cost of 135
After the above, the next 5 calendar days are at a cost of 160
After that 180 onward.
is this possible to do in excel? My idea is to have a difference between 2 dates: date of arrival versus date of return. and based on the 4 rules below use "IF" to give me a cost.
what would be a more efficient way to do this?
HardCoded option:
With Dynamic array formula SEQUENCE()
=SUM(IF(SEQUENCE(B1-A1+1,,A1)<WORKDAY(A1,5),0,IF(SEQUENCE(B1-A1+1,,A1)<WORKDAY(A1,5)+3,135,IF(SEQUENCE(B1-A1+1,,A1)<WORKDAY(A1,5)+8,160,180))))
Older version:
=SUM(IF(ROW(INDEX($ZZ:$ZZ,A1):INDEX($ZZ:$ZZ,B1))<WORKDAY(A1,5),0,IF(ROW(INDEX($ZZ:$ZZ,A1):INDEX($ZZ:$ZZ,B1))<WORKDAY(A1,5)+3,135,IF(ROW(INDEX($ZZ:$ZZ,A1):INDEX($ZZ:$ZZ,B1))<WORKDAY(A1,5)+8,160,180))))
As an array formula, using Ctrl-Shift-Enter to confirm instead of Enter when exiting edit mode.
Using a lookup table.
Put 0 in the first cell in the lookup table. The second cell would get the formula =WORKDAY(A1,5) the next below: =F2+3 and the last =F3+5 and put the corresponding values:
Then use SUMPRODUCT and LOOKUP:
=SUMPRODUCT(LOOKUP(SEQUENCE(B1-A1+1,,A1),F1:F4,G1:G4))
older version:
=SUMPRODUCT(LOOKUP(ROW(INDEX($ZZ:$ZZ,A1):INDEX($ZZ:$ZZ,B1)),F1:F4,G1:G4))
Below is a VBA function that accepts three arguments - the start date, the end date, and the name of the carrier, and returns a cost. Only costing for one carrier is included, but it can be expanded for other carriers.
Function fContainerCost(dtmStart As Date, dtmEnd As Date, strCarrier As String) As Currency
Dim lngDays As Long
Select Case strCarrier
Case "CarrierA"
dtmStart = WorksheetFunction.WorkDay(dtmStart, 5)
If dtmStart > dtmEnd Then
fContainerCost = 0
Else
lngDays = DateDiff("d", dtmStart, dtmEnd) + 1 ' need to get the actual days, so get the difference in dates and add 1.
If lngDays <= 3 Then
fContainerCost = fContainerCost + (135 * lngDays)
Else
fContainerCost = fContainerCost + (135 * 3)
lngDays = lngDays - 3
If lngDays <= 5 Then
fContainerCost = fContainerCost + (160 * lngDays)
Else
fContainerCost = fContainerCost + (160 * 5)
lngDays = lngDays - 5
fContainerCost = fContainerCost + (180 * lngDays)
End If
End If
End If
Case "CarrierB"
End Select
End Function
To use it, just treat it as a regular Excel function:
=fContainerCost(A1,B1,C1)
Regards,

Performing calculation of two separate case statements

I have created a saved search in NetSuite which displays two separate case statements.
1- case when {transaction.type} = 'Item Receipt' and {transaction.account} = '5505 Cost of Goods Sold : Product Cost' or {transaction.type} = 'Item Fulfillment' and {transaction.account} = '5505 Cost of Goods Sold : Product Cost' then {transaction.amount} else null end
2- case when {transaction.type} = 'Invoice' or {transaction.type} = 'Cash Sale' or {transaction.type} = 'Cash Refund' or {transaction.type} = 'Credit Memo' then {transaction.amount} else null end
Now I need to add third column in which I can display % by dividing result values between case case statement 1 and 2. Any advise how is that possible? Thanks!
As Brian mentioned (and I presume you are doing) grouping is the easiest way.
You can use Minimum (as shown), Maximum, or Average for the Formula (Percent) field.
The IN statement shown above would also simplify your formulas.
Edit:
To avoid the Possible Divide by Zero error:
SUM(case when {transaction.account} = '5505 Cost of Goods Sold :Product Cost' and {transaction.type} in ('Item Fulfillment','Item Receipt') then {transaction.amount} else 0 end) / NULLIF( SUM(case when {transaction.type} in ('Invoice','Cash Sale','Cash Refund','Credit Memo') then {transaction.amount} else 0 end) ,0)

Determine student's year of study, or whether they are have graduated

I need a function that can determine whether a student is in their first, second or third year of study, or whether they are have graduated based on a) the certificate they're studying for and b) the date on which they started.
Here's my first effort - any feedback would be greatly appreciated:
[EDIT: The problem is that the function returns an error when using it in Excel]
[EDIT2: changed the m in the DateDiff section to "m" which knocked out the error - now there's just the problem that 2nd and 3rd year students are being labelled as 'Past']
Function YearCalc(start, course)
'Introduce length - the course length in years
Dim length As Integer
'Define length corresponding to specific courses
If course = "Msc" Then
length = 3
ElseIf course = "Adv Dip" Then
length = 2
ElseIf course = "PG Cert" Then
length = 1
End If
Dim lengthm As Integer
lengthm = (length * 12)
'Define diff as the month difference between two dates;
'today's date and the date the course was started.
diff = DateDiff("m", start, Date, vbMonday)
'Compare the date difference to the length of the course,
'such that if the difference is larger than length of the specific course
'the student is marked as 'Past':
If diff >= (lengthm) Then
YearCalc = "Past"
'If the difference is less than the length of the course, determine which
'year they fall into:
Else
If 0 <= (diff - lengthm) < 1 Then
YearCalc = 1
ElseIf 1 <= (diff - lengthm) < 2 Then
YearCalc = 2
ElseIf 2 <= (diff - lengthm) < 3 Then
YearCalc = 3
End If
End If
End Function
I would suggest changing to Select Case, as part of the reason for only returning 1 value is the double comparison.
0 <= AnyComparison will always evaluate to True
Select Case course
Case "Msc"
length = 36
Case "Adv Dip"
length = 24
Case "PG Cert"
length = 12
End Select
and
Select Case (diff - lengthm)
Case <0
YearCalc = "Past"
Case 0 to 11
YearCalc = 1
Case 12 to 23
YearCalc = 2
Case 24 to 35
YearCalc = 3
Case Else
YearCalc = "Course too long?"
End Select

Resources