Grouping Classes & Subclasses in saved search - netsuite

I'm trying to create a saved search that sums total sales by the parent class. I'm trying a CASE statement but can't seem to get it to work. This is what I have:
CASE
WHEN {class} LIKE 'B2B%’ THEN 'B2B'
WHEN {class} LIKE 'Amazon%’ THEN 'Amazon'
WHEN {class} LIKE 'Website%’ THEN ' B2C'
ELSE ‘’
END

Not sure why but that format never works for me either, although Netsuite documentation suggests that it should/does. Try nested CASE statements.
CASE WHEN {class} LIKE 'B2B' THEN 'B2B' ELSE
CASE WHEN {class} LIKE 'Amazon%' THEN 'Amazon' ELSE
CASE WHEN {class} LIKE 'Website%' THEN ' B2C' ELSE '' END
END
END
Or you can use SUBSTR({class},0,INSTR({class},':')-2) to get just the part of the string before " :", assuming all of your classes have these characters present.
Once you have that column formula working, group results based on this formula, add total sales as a column and group that but select "Sum".

Related

Cognos Report Studio: CASE and IF Statements

I'm very new in using Cognos report studio and trying to filter some of the values and replace them into others.
I currently have values that are coming out as blanks and want to replace them as string "Property Claims"
what i'm trying to use in my main query is
CASE WHEN [Portfolio] is null
then 'Property Claims'
ELSE [Portfolio]
which is giving me an error. Also have a different filter i want to put in to replace windscreen flags to a string value rather than a number. For example if the flag is 1 i want to place it as 'Windscreen Claims'.
if [Claim Windscreen Flag] = 1
then ('Windscreen')
Else [Claim Windscreen Flag]
None of this works with the same error....can someone give me a hand?
Your first CASE statement is missing the END. The error message should be pretty clear. But there is a simpler way to do that:
coalesce([Portfolio], 'Property Claims')
The second problem is similar: Your IF...THEN...ELSE statement is missing a bunch of parentheses. But after correcting that you may have problems with incompatible data types. You may need to cast the numbers to strings:
case
when [Claim Windscreen Flag] = 1 then ('Windscreen')
else cast([Claim Windscreen Flag], varchar(50))
end
In future, please include the error messages.
it might be syntax
IS NULL (instead of = null)
NULL is not blank. You might also want = ' '
case might need an else and END at the bottom
referring to a data type as something else can cause errors. For example a numeric like [Sales] = 'Jane Doe'
For example (assuming the result is a string and data item 2 is also a string),
case
when([data item 1] IS NULL)Then('X')
when([data item 1] = ' ')Then('X')
else([data item 2])
end
Also, if you want to show a data item as a different type, you can use CAST

Combining two separate case statements in NetSuite Case Statements

I currently have two separate saved search columns for these two statements, and I'm hoping to combine them and list the data in just one column. I've tried OR AND, but the results then error out.
First Statement
Case when {item.custitem54} is null then {quantity} else null end
Second Statement
Case when {item.custitem54} = 'Yes' and {shipdate} between to_date('05/25/2020', 'MM/DD/YYYY') and to_date('12/25/2020', 'MM/DD/YYYY') then {quantity} else null end
You can have multiple WHEN in a case statement. The first matched WHEN determines the result unless it gets to the ELSE.
Case when {item.custitem54} = 'Yes'
and {shipdate} between date '2020-05-25' and date '2020-12-25' then {quantity}
when {item.custitem54} is null then {quantity}
else null
end

IF statement to determine date

I want to set an order completion date based on the words Standard or Rush.
Currently I have it set up where if a cell shows the word Standard, it will give me a date, but once I try to add Rush to that, it get errors
=IF(ISNUMBER(SEARCH("VF",B2)), IF(J2="Standard", WORKDAY(TODAY( )+2,1)), "")
I also tried this, but when I type Rush into J2, the result shows as just FALSE
=IF(ISNUMBER(SEARCH("VF",B2)), (IF(J2="Standard", WORKDAY(TODAY( )+2,1))), (IF(J2="Rush", WORKDAY(TODAY( )+1,1))))
The idea here is to make an order wanted date based on the Rush and Standard time frame.
You have embedded your new IF function inside of the wrong if.
This: (IF(J2="Standard", WORKDAY(TODAY( )+2,1))) is going to return a date or FALSE. You want to change that FALSE to return your next IF statement. Instead:
=IF(ISNUMBER(SEARCH("VF",B2)), IF(J2="Standard", WORKDAY(TODAY( )+2,1), IF(J2="Rush", WORKDAY(TODAY( )+1,1))), "")
You return nothing "" in the case that your ISNUMBER() fails still.

Trying to orderby with case when clause for MultiDocumentQuery?

I am trying to get all my pagetypes from kentico, but I would like to order them by all the page types that starts with the letter "F", first and then the other pages alphabetically.
What I am trying is:
1) MultiDocumentQuery docQuery = DocumentHelper.GetDocuments().Type("forms").OnSite(SiteContext.CurrentSiteID).Published();
2) docQuery.OrderBy("FormName");
But what I need is to order em using something like this (SQL):
SELECT FormName
FROM Forms
order by
case when FormName like 'C%' then 0 else 1 end,
FormName
What I cant do is to translate the case when properly to c#, and implement it to docQuery.
So the result should be for example,:
Form1
Form2
Form3
A...
B...
I think I'd look at adding your case statement in the columns rather then the where like this:
CASE WHEN FormName LIKE 'F%' THEN 0 ELSE 1 END AS IsForm
This way you can have a new column called IsForm and can have an Order by of:
IsForm, FormName

select case with variable boolean operator

This is my first question on the forum, but reading previous questions has been enormously helpful in the project I'm working on, so already my thanks. I couldn't find an answer to this, but apologies if I overlooked something.
I am writing an excel macro in vba, and am trying to create a select case... statement in which the expression has a variable boolean and numeric component. For example, the macro can pull "> 3" or "< 3" from another worksheet.
My hope had been that I could assign to a string all of these parameters, i.e.:
test1 = "is " & BoolOperator1 & " " & NumericValue1
and then
Select case ValuetoCompare
Case test1
'Do something
Case test2
'...
Is there a way to do this? I suppose the alternative would be to nest the case with the numeric variable inside a select function that determines the operator, but I thought this would be more elegant.
Thanks in advance for your guidance--
Josh
Assuming that you'll get a string BoolOperator1 that is a valid operator, e.g. >=, =, and a numeric value NumericValue1, the easiest way to execute this comparison on another numeric value ValueToCompare is to use the Evaluate function. This will execute a string as VBA and return it's result.
In your case, you could simply use:
If Evaluate(ValueToCompare&BoolOperator1&NumericValue1) Then ...
If you want to use this in a Select Case statement, you'd either need to use a simple If ... ElseIf ... statement - or use this trick:
Select Case True
Case Evaluate(ValueToCompare&BoolOperator1&NumericValue1): ...
Case Evaluate(ValueToCompare&BoolOperator2&NumericValue2): ...
Case Else ...
End Select

Resources