I am trying to create a visualisation where i can see where a product has passed 2 tests: test=overall and test=flash (these are part of the same column). then there is a column result which can be pass/fail. i want both of these tests to be pass and then i want to count the distinct products. I then want to include this figure in a dashboard that updates.
I think I want a LOD but not sure where to start. is this something i do in desktop or prepenter image description here
I am new to Tableau so LOD is something i am trying to get my head around
Use the below calculation,
if {fixed [Device]: min([Result])}='fail' then False else TRUE end
Pull this field to filter shelf and select TRUE to get only devices which pass both tests
You didn’t say how to treat devices that have both pass and fail entries for one of your tests. This expression tests whether a device has passed at least one overall test and at least one flash test. You could also use a version of this to define a set if you preferred
{ fixed [Device] : max([test] = “overall” and [Result] = “pass”) and
max([test] = “flash” and [Result] = “pass”) }
The key concept is that MIN() and MAX() operate on boolean arguments to return boolean values, treating True values and greater than False values. So MAX() tests whether the condition is ever satisfied; i.e. it returns true if the condition evaluates to true for at least one of the data records. Likewise, MIN() tests whether the condition is always satisfied; i.e. it returns true if the condition evaluates to true for every one of the data records.
If the condition ever evaluates to null, MIN() and MAX() ignore null values just like all other aggregation functions. So if that is an issue in your case, you can use IFNULL() around your expression to provide a default value.
Related
I have a Set Variable activity which uses the logic:
#range(int(pipeline().parameters.start),int(pipeline().parameters.end))
It is wierd that I cant find any logic in documents where I can mention a step so that I can generate few numbers as shown below
1,3,5,7,9,...
Is there work around to it, other than introducin a new parameter that is equal to step and generate next number using logic last = last+step.
It is possible to do this using the Filter activity and the range function. Use the range function to generate all numbers and then the Filter condition with mod to get odd numbers, ie
Property
Value
Items
#range(1,10)
Condition
#equals(mod(item(),2),1)
A screenprint of the results:
The other way to do it would be just use a Lookup activity and query a numbers table.
I agree with you that it's a shame range does not have a step argument, and that generally the ADF expression language isn't a bit more fully featured.
I have a SQL select statement that reads items. There are conditions for which items to display, but when one condition fails, I don't need to check the other.
For example:
where item like 'M%'
and item_class='B'
and fGetOnHand(item)>0
If either of the first 2 fail, i do NOT want to do the last one (a call to a user defined function).
From what I have read on this site, SQL Server's AND and OR operators do not follow short circuiting behavior. This means that the call to the UDF could happen first, or maybe not at all, should one of the other conditions happen first and fail.
We might be able to try rewriting your logic using a CASE expression, where the execution order is fixed:
WHERE
CASE WHEN item NOT LIKE 'M%' OR item_class <> 'B'
THEN 0
WHEN fGetOnHand(item) <= 0
THEN 0
ELSE 1 END = 1
The above logic forces the check on item and item_class to happen first. Should either fail, then the first branch of the CASE expression evaluates to 0, and the condition fails. Only if both these two checks pass would the UDF be evaluated.
This is very verbose, but if the UDF call is a serious penalty, then perhaps phrasing your WHERE clause as above would be worth the trade off of verbose code for better performance.
How do you aggregate strings in Tableau? For example, at the detail level I have values of Yes and No but at the aggregated level I only want to show one of those values
For example, if the aggregation has a No in it then Show No otherwise show Yes.
i.e. if the level of detail contains a No then show no otherwise show Yes.
It would be a tad simpler if you used Boolean values instead of strings - also that would enforce that there were only two legal values. If your field, say it is called Completed, contained Boolean values (I.e. either TRUE or FALSE), then to show whether all records were completed, I.e. had the value TRUE in the Completed Column, you would simply use MIN([Completed]).
This works because Tableau treats True as greater than False, so MIN(condition) is true if and only if condition is True for every record - ignoring nulls. MAX(condition) is true if and only if there is at least one record with condition set to True. So for Booleans, you can read MIN() as “every” and MAX() as “any”.
The one wrinkle is if your boolean field allows null values. If so, you can decide between a few options. You can take the default behavior which is to silently ignore nulls as if they don’t exist, or you can wrap the field reference in a call to IFNULL() to supply a default value of your choice to replace the nulls. Really the same for any data type and aggregation function.
This technique is useful in several situations, including defining conditions for sets.
Finally, if your data set has to use strings such as “YES” and “NO” instead of booleans, you can convert to booleans easily by defining a new calculated field such as Completed as [Completed-Original] = “YES”
Using OrientDB 2.1.2, I was trying to use the inherent COALESCE functionality and ran into some strange results.
Goal: select the maximum value of a property based on certain conditions OR 0 if there is no value for that property given the conditions.
Here's what I tried to use to produce my results.
Attempt 1: Just selecting the Maximum value of a property based on some condition - This worked as I expected... a single result
Attempt 2: Same query as before but now I'm adding an extra condition that I know will cause no results to be returned - This also worked as I expected... no results found
Attempt 3: Using COALESCE to select 0 if the result from the second query returns no results - This is where the query fails (see below).
I would expect the result from the second query to return no results, thereby qualifying as a "NULL" result meaning that the COALESCE function should then go on to return 0. What happens instead is that the COALESCE function is seeing the results of the inner select (which again, returns no results) as a valid non-null value, causing the COALESCE function to never return the intended "0" value.
Two questions for those who are familiar with using the OrientDB API:
Do you think this functionality is working properly or should an issue be filed with the orientdb issue tracker?
Is there another way to achieve my goal without using COALESCE or by using COALESCE in a different way?
Try rather:
select coalesce($a, 0) from ... let $a = (subquery) where ...
Or also this variant because the sub-select returns a result set, but the coalescence wants a single value:
select coalesce($a[0], 0) from ... let $a = (subquery) where ...
In my frontend application I have a function that is called pick(VALUE,'col1','col2','col3'). If the VALUE is 2 the value in col2 should be picked.
This is very handsome for replacing long code using "case when", "switch case" or "if else" calculations.
I have tried to find a similar function in Postgres, but no luck so far. Seen some function array() and values() mentioned, but cannot find the correct syntax.
The goal is to set an return on of three column values depending on first column value.
Pseudo code (not working):
Select status values(column1,column2,column3)from code
I know I can do this by using "case-when-then-else-end", but I am looking for a shorter way to achieve the same thing.
Jsfiddle showing the principe. But I only want to pick ONE value depending on type:
http://sqlfiddle.com/#!15/e0b41/10
You can create an array of values from pr_* columns, then pick one of them in this way:
(array[prl_1,prl_2,prl_3])[code_type]
Here is a simple demo: http://sqlfiddle.com/#!15/e0b41/23
select *,
(array[prl_1,prl_2,prl_3])[code_type]
from code
left join prl on prl_id =1