If I take the dual form of a boolean expression and simplify it using some other theorems, after I'm done simplifying, do I need to take the dual of it again to obtain the original expression?
The answer is yes, you need to take the dual of it again.
Related
I need help on a basic calculation that I'm unable to figure on Tableau.
I am trying to setup a calculated field that has dependency on its previous value to calculate its current value. Here is a simple example from Excel -
Sample Exhibit
As you can see, each value in a row is dependent on its previous value and multiplied by a constant.
In Tableau, when I'm trying to create a calculated field, it is not letting me refer to itself (-1 lagged value) in the code. I'd appreciate any help on how this can be resolved. Thanks in advance!
Tableau can do this client side with a table calc. You’ll have to learn how table calcs operate from the help- especially partitioning and addressing. Then you can use the function Previous_Value() to refer to the previous value. Practice on something simple first to make sure you understand how previous value() works. Hint, the argument to that function doesn’t mean what most people assume it means
If you want to perform this calculation server side instead, then you’ll need to use custom SQL so you can specify an analytic aka windowing query
Check the LOOKUP field to get the value from the preceding row. For example: LOOKUP(SUM([Value]),-1)
https://help.tableau.com/current/pro/desktop/en-us/functions_functions_tablecalculation.htm#lookupexpression-offset
You may need to make yourself familiar with the Table Calculation partitioning if not getting the expected result.
How can I turn the next query:
SELECT Column1, Column2 FROM Table WHERE Column3 < 15
Into Power Query M, I can only perform the first part:
= Table.SelectColumns(#"Table", {"Column1", "Column2"})
If you prefer single step:
= Table.SelectRows(Table, each [Column3] < 15)[[Column1],[Column2]]
Although I use the so-called "Advanced Editor" every day, I'd recommend using the step editor for this query. PowerQuery will then understand how to fold the query (translate the initial steps into SQL) because it generated the M. You can see the SQL from the context menu on a step "View Native Query". This will continue for many of the steps you might add later, such as column renames and calculated columns.
If you start with SQL or get to the point of non-foldable step, including from writing the M code yourself, none or only some of the M is translatable into SQL.
Alternatively (perhaps you know this already), you can put whatever SQL you want straight into the first step using the step editor.
This may be an easily solvable question but I can't see an immediate solution. I am calling a PostgreSQL function which returns multiple columns, 2 of which are relevant to this question - a date column & a numeric field of return values. An example of the function call would be
SELECT curr_date, return_val
FROM schema.function_name($1,$2);
With example output such as
"2014-07-31";0.003767
"2014-08-07";-0.028531
"2014-08-14";0.020051
"2014-08-21";-0.003541
"2014-08-28";0.007766
"2014-09-04";-0.021926
"2014-09-11";0.026330
"2014-09-18";0.008137
"2014-09-25";-0.033303
"2014-10-02";0.030100
"2014-10-09";-0.012116
"2014-10-16";-0.017148
So on, so forth. The data will always return from this function with the dates ascending. What I would like to do is to use Postgres's stddev_samp function on every row, but only considering the return_value's from that row's date back in time. Something like:
SELECT curr_date, return_val,
--stddev_samp(return_val) where curr_date <= curr_date of current row
FROM schema.function_name($1,$2);
Naturally, if I calculated the sample deviation of the return_value's from 2014-07-31 to 2014-10-02 in the sample provided, it would differ slightly to calculating it using the result set from 2014-07-31 to any other date present. I know I could probably write another function which takes a numeric array as input and returns the standard deviation as output, and then call this in my query above, but I'm hoping someone may have a simpler approach which I'm just currently not seeing. If any other information is required, feel free to ask. I'm using version 10.7.
demo:db<>fiddle
Using window functions:
SELECT
stddev_samp(return_val) OVER(ORDER BY curr_date)
FROM
mytable
Sorry if this seems trivial, but I am fairly new to Tableau. I have a simple table that has 1 dimension for columns and 1 dimension for rows. My Marks are the Count of a third dimension. I'd like to divide only 1 of the columns in the table by a constant but not all of them. When I have tried conditional statements, I receive the error regarding mix of non-aggregate and aggregate statements.
What is the best way to divide a single column's values based upon a condition?
Thanks in advance.
Typically the error regarding non-aggregate and aggregate statements can be resolved using the ATTR() function.
SUM([Sales]) / [Constant]
Turns to:
SUM([Sales]) / ATTR([Constant])
Or conversely, which might or might not fit your data:
[Sales] / [Constant]
You just cant mix the two as in the first example.
Edit
This is probably a more accurate place for the ATTR() function given what I'm guessing is your use case:
If ATTR([Segment]) = 'Corporate'
Then COUNT(Sales) / SUM([Constant])
END
Try turning the constant to a discrete measure and see if that works. (right-click on measure and select 'discrete')
Also, without seeing the conditional code you are using, you probably need to wrap the entire condition with count() in order to not get the Aggregate/Non-Aggregate error, like this:
Count(If [MyDimension] = "XX" then [MyOtherDimension] else Null End)
NOT like this:
If [MyDimension] = "XX" then Count([MyOtherDimension]) else Null End
We use the H2 database engine as part of our test tooling for a product that uses SQL Server 2012 in production. Some of the existing SQL views use the three-argument CONVERT function on dates to format them as "ODBC Canonical" date:
CONVERT(VARCHAR, some_date, 120)
Normally when we encounter a situation like this we do one of the following two things:
we replace the SQL with something portable that works in MS SQL and H2
we implement a JAVA function to match MS SQL's behaviour and map it as UDF into H2
At the moment both seem to fail us since MS SQL doesn't seem to offer an alternative way of formatting dates and CONVERT is already a function in H2, just not in the three argument form.
We seem to be left with two options that we don't really like:
add a layer of in-direction on both sides, by defining a UDF in MS SQL that runs the convert, with a corresponding one in H2,
patch H2
The issue with the former is that it will introduce something into production that is solely for testing. That is true to some extent for migrating to more portable SQL as well, but adding the UDF is going a step further.
Patching H2 could be an option, but it is hard to tell how much effort that would be, in particular considering the existing CONVERT function. If suitable for a wider audience we would have to also cover MS SQL's weird world of styles across the types in a reasonable fashion, whereas we are only after one style for dates.
Is there another way? Has anyone experience with solving this problem?
The equivalent result using the FORMAT function is:
SELECT FORMAT(GETDATE(),'yyyy-MM-dd HH:mm:ss');
It seems that using the FORMAT function instead of CONVERT may resolve your issue.
Another way without using CONVERT is this:
SELECT
CAST(YEAR(GETDATE()) AS VARCHAR(4)) + '-' +
CAST(MONTH(GETDATE()) AS VARCHAR(2)) + '-' +
CAST(DAY(GETDATE()) AS VARCHAR(2))
(this is just an example and does not contain time components)