How do add additional nested if else statements? AWS Quicksight - amazon-web-services

I have a working If else statment as below
ifelse({location_building_code} ='XC',ifelse({shift_pattern_code}='AAAA','AM-FT',{shift_pattern_code}),
ifelse({location_building_code} ='XA',ifelse({shift_pattern_code}='AAAA','AM-FT', {shift_pattern_code}),{shift_pattern_code}))
however i would like to add in additional If statement.
ifelse({location_building_code} ='XC', ifelse({badge_type} = 'Green', ifelse({shift_pattern_code}='AAAA','AM-FT',{shift_pattern_code}),
ifelse({location_building_code} ='XA', ifelse({badge_type} = 'Green', ifelse({shift_pattern_code}='AAAA','AM-FT', {shift_pattern_code}),{shift_pattern_code}),{shift_pattern_code})))
However I get syntax error I would like to expand to inlucude more nested if's
expected outcome to be able to have IF else Building = x the badge type x then define Shift codes by actual meaning rather than code as long as multiple conditions are met.

Related

Should I reimplement the logic in property based test?

Let's say there is a function to determine if a button should be visible.
fun isButtonVisible(fitlers: List<Filters>, results: List<Shop>, isLoading: Boolean) {
return fitlers.isNotEmpty() && results.isEmpty() && !isLoading
}
Now I would like to test this function using PBT like:
"the button should be visible if filters is not empty and results is empty and is not loading" {
forAll { filters: List<Filters>, results: List<Shop>, isLoading: Boolean ->
val actual = isButtonVisible(filters, results, isLoading)
// Here reimplement the logic
val expected = filters.isNotEmpty() && results.isEmpty() && !isLoading
assertThat(actual).isEqual(expected)
}
}
It seems that I just reimplement the logic again in my test, is this correct? If not, how can I come up with another properties if the logic is just simple combinations of several flags?
that is not right.
you should not have to calculate what the expected value should be during the test, you should know what the result should be, set it as such and compare it against the actual result.
Tests work by calling the method you want to test and comparing the result against an already known, expected value.
"the button should be visible when filters are not empty, results is empty, isLoading is false " {
forAll { filters: List<Filters>, results: List<Shop>, isLoading: Boolean ->
val actualVisibleFlag = isButtonVisible(filters, results, isLoading)
val expectedVisibleFlag = true
assertThat(actualVisibleFlag ).isEqual(expectedVisibleFlag )
}
}
Your expected value is known, this is the point I am trying to make.
For each combination of inputs, you create a new test.
The idea here is that when you have a bug you can easily see which existing test fails or you can add a new one which highlights the bug.
If you call a method, to give you the result of what you think you should get, well, how do you know that method is correct anyway? How do you know it works correctly for every combination?
You might get away with less tests if you reduce your number of flags maybe, do you really need 4 of them?
Now, each language / framework has ( or should have ) support for a matrix kind of thing so you can easily write the values of every combination

Program isn't giving correct results - case when (SAS)

/* FLAG_MISMATCH_PAID*/
(CASE
WHEN t1.Paid=t2.PAID_AMT THEN "TRUE"
ELSE "FALSE"
END) AS FLAG_MISMATCH_PAID
This works when I am using other variables, but for some reason I am getting incorrect TRUE/FALSE results when I use this code. I thought maybe there was some issues with numbers beyond the hundreds unit so I tried using round (x, .01), but correcting for that made no difference.
Why would two numbers that are exactly the same still give me a "FALSE" result? (i.e. t1.Paid = $106,115.23 and t2.PAID_AMT = $106,115.23, and it is flagged as FALSE, yet t1.Paid =$57,242.11 and t2.PAID_AMT = $57,242.11 is TRUE)

IF Formula returning error or not doing a section of the formula

I have a formula in my report to select a field based on requirements:
if not isnull({EXT_TBL.EXT_KEY_TYPE}) then
(if {EXT_TBL.EXT_KEY_TYPE} = "SO" and {EXT_TBL.EXT_ACTION_FLAG_9} = "Y"
then {EXT_TBL.EXT_TEXT})
else '0'
When I run the report it works ok until I try to load a specific page. When I try to load the page I get an error of 'The string is non numeric'. The formula is called in another formula:
{COR_TBL.COR_EXPECTED_DATE} + 2 + ToNumber({#FRM_NOTES})
I have ran the query on the server of:
SELECT * FROM EXT_TBL WHERE EXT_KEY_TYPE = "SO" AND EXT_ACTION_FLAG_9 = "Y";
This returned me two rows of data. I have narrowed it down to a specific entry that is causing the issue, but in the database the row has N in the field action flag 9 instead of Y so it shouldn't be throwing me the error in my report.
The action field 9 is flagged on only two records both of which contain a 7 in the EXT_TEXT feild so I have no idea why I am getting the error.
I also tried a nested if statement of:
if not isnull({EXT_TBL.EXT_KEY_TYPE}) then
(if {EXT_TBL.EXT_KEY_TYPE} = "SO" then (if {EXT_TBL.EXT_ACTION_FLAG_9} = "Y"
then {EXT_TBL.EXT_TEXT}))
else '0'
But it still gave me the same error.
Thanks
I was able to fix the issue by removing the nested if statement and just putting all the conditions in the original statement:
if not isnull({EXT_TBL.EXT_KEY_TYPE}) AND {EXT_TBL.EXT_KEY_TYPE} = "SO"
AND {EXT_TBL.EXT_ACTION_FLAG_9} = "Y"
THEN {EXT_TBL.EXT_TXT} ELSE '0'
This seems to have fixed the issue.

How to cast expression in select clause with high performance

I have a table and want to convert a column of type decimal to an integer based on a condition. I need to do this as performant as possible.
My currently working query looks like this:
select *, (case when C_CUSTKEY < 20 then 1 else 0 end) as bit
from TPCH.CUSTOMER
However I'm trying to improve this. Is it possible to do the conversion on the fly, e.g. something like this:
select *, cast((C_CUSTKEY < 20) as integer) as bit
from TPCH.CUSTOMER
Or even for a simpler version like:
select *, (C_CUSTKEY < 20) as bit
from TPCH.CUSTOMER
No matter what functionality I use, I always get the following error:
sql syntax error: incorrect syntax near "<"
Update 1
So for better understanding an actual usecase of what I want to do is as following:
select ( (case when col1 < x then 1 else 0 end)
+ (case when col2 > y then 2 else 0 end) ) as bitset
from TPCH.CUSTOMER
In general there can be a large number of 'case when' expressions (>100).
Now the first problem is that the expression is very slow and I need to improve performance so I wanted to know if its possible to to the conversion on the fly smth like 2 * to_int(col2 > y) but I cannot find a way to do this.
Second problem is when I have many 'case when' expressions then I get the following error: SQL internal parse tree depth exceeds its maximum: parse tree depth exceeds its maximum:255
Not quite sure about the use case here.
Generally speaking, you cannot have a different data type for the same column at the same time. That's a fundamental constraint of the relational data model.
If however, the requirement merely is to have an indicator for "value in C_CUSTKEY < 20" then using the CASE statement is a straightforward way to do this.
In order to avoid this evaluation at query time, you could create a calculated column for this.
alter table TPCH.CUSTOMER add ("BIT" integer
generated always as
case
when ("C_CUSTKEY" < 20)
then 1
else 0
end);
Concerning the syntax errors: well, you're just not using the correct syntax. Check the example above for a correctly working example.

If statement in Thinkscript

I am a beginning thinkscript programmer and I am learning the syntax of thinkscript pretty fast. However, I am having trouble with the if statements. I understand you can have one statement inside of an if block but is it possible to have multiple statements in an if block?
Not: if (condition) then (this) else (that);
but: if (condition) then { (this); (that);};
thinkScript essentially has three forms of if usage. All three forms require an else branch as well. One form allows for setting or plotting one or more values. The other two only allow one value to be set or plotted.
if statement: can set one or more values, for plot or def variables, within the brackets.
def val1;
plot val2;
if (cond) {
val1 = <value>;
val2 = <value>;
} else {
# commonly used options:
# sets the variable to be Not a Number
val1 = Double.NaN;
# sets the variable to what it was in the previous bar
# commonly used for recursive counting or retaining a past value across bars
val2 = val2[1];
}
if expression: all-in-one expression for setting a value. Can only set one value based on a condition, but can be used within other statements. This version is used commonly for recursively counting items across bars and for displaying different colors, say, based on a condition.
def val1 = if <condition> then <value if true> else <value if false>;
if function: similar to the above, but more compact, this is thinkScript(r)'s version of a ternary conditional statement. It's difference is that the true and false values must be double values. Therefore, it can't be used in setting colors, say, or other items that don't represent double values.
def var1 = if(<condition>, <value if true>, <value if false>);
The following example, modified from the thinkScript API doc for the if function, demonstrates using all three versions. I've added a 2nd variable to demonstrate how the if statement can set multiple values at once based on the same condition:
# using version 3, "if function"
plot Maximum1 = if(close > open, close, open);
# using version 2, "if expression"
plot Maximum2 = if close > open then close else open;
# using version 1, "if statement", with two variables, a `plot` and a `def`
plot Maximum3;
def MinimumThing;
if close > open {
Maximum3 = close;
MimimumThing = open;
} else {
Maximum3 = open;
MinimumThing = close;
}
As a side note, though the example doesn't show it, one can use the def keyword as well as the plot keyword for defining variables' values with these statements.
It is possible. Just mistaken plot variables for conditional statements since they, in turn, use conditional statements to draw out the graphics.