K2 blackpearl: Create DateTime[] from data fields - k2

I cannot figure out how to use the DateTime Maximum function with multiple data fields. I have 2 (DateTime) data fields that I want to get the maximum value.
The "values" field only lets you type a literal or drop in ONE field. How can I create an array of my 2 fields?
Thank you!

Ob
I think the problem you are having is that the input is not a date but an array of dates: DateTime[]
I don´t think this function is typically made to help you find the biggest between 2 dates in 2 datafields.
The way this function works is that you need to give it an array and of course the second param is a date.
To do so, you can use a smartobject that will return you a list of datetime (when you call the list, make sure you don´t return just the first, this is the default value).
The function will then work fine and tell you which of the dates in this list is the 'maximum'.
Now, if you really have to use the dates in those datafields, you will first need to convert those 2 datetime into an array of datetime. Unfortunately, I am not aware of a function able to do that (I may be wrong...).
I see 3 options nonetheless:
You write a custom function that will do just that: take 2 input and return an array of them (there are Knowledge Base article explaining how to do that)
You use a stored procedure (that you call thru a smart object) that converts your 2 data into an array and you then can use the function you mentioned
3 . I think you may simplify even further by letting the stored procedure find the max for you. See below.
A simple version for #3 would be:
declare #D1 datetime
declare #D2 datetime
SET #D1 = getdate()
SET #D2 = getdate()+100
if (#D1>#D2)
select #D1
else
select #D2
I hope this helps.

Related

Using SELECT IF to recode one date from four variables in SPSS

Self-taught at SPSS here. Need to know the appropriate syntax to recode four DATE variables into one, based on which would be the latest date. I have four DATE variables in a dataset with 165 cases:
wnd_heal_date
wnd_heal_d14_date
wnd_heal_d30_date
wnd_heal_3m_date
And each variable may or may not contain a value for each case. I want to recode a new variable which scans the dates from all four and only selects the one that is the latest and puts it into a new variable (x_final_wound_heal_date).
How to use the SELECT IF function for this purpose?
select if function selects rows in the data, and so is not appropriate for this case. What you can do is this instead:
compute x_final_wound_heal_date =
max(wnd_heal_date, wnd_heal_d14_date, wnd_heal_d30_date, wnd_heal_3m_date).
VARIABLE LABELS x_final_wnd_heal_date 'Time to definitive wound healing (days)'.
VARIABLE LEVEL x_final_wnd_heal_date(SCALE).
ALTER TYPE x_final_wnd_heal_date(DATE11).
This will put the latest of available date values in the new variable.

I need to split a text column in Access that stores dates in MM/YYYY and MM/DD/YYYY format to remove the day format

I have a program that writes dates as text in a column called Expression. Is there a way to write a query that will remove the day of the month? I need it to be something that I can share with multiple people to use in multiple databases. Examples of the format of the values stored are 6/2021, 06/2021, and 06/01/2021.
You can use IIf in the query to compare the length of the data, and pad/split as required. Something like:
SELECT
Expression,
IIf(Len([Expression])=6,"0" & [Expression],IIf(Len([Expression])=7,[Expression],IIf(Len([expression])=10,Left(Expression,2) & "/" & right(expression,4)))) AS OutputData
FROM tblFormatDate;
You may need to add a few more IIfs, and also a final false return statement. If it starts to get messy with the data, then you may want to look at creating a custom VBA function that makes the process flow easier to understand.
Regards,

how do i compare values and assign condition in tableau?

I have a table with members, date and results. The date represent the month for which all the results were generated for various members. Table stores results for multiple months. Now, i want to compare results of current month with last month for particular member and assign “equal” , “>” or “<” sign based on their values. How can i do that in tableau?
Any help is greatly appreciated!
Thank you.
You can use the lookup function. Assuming you have below data:
you can create a lookup function in tableau with below expression:
LOOKUP(sum([Result]),-1)
Note you need to use an aggregate function on your measure
After creating a lookup column create a calculated field to do data comparison:
This should give you the result you are looking for:
You can edit the table calculations to define the reset level for your calculation:

PostgreSQL Rolling Standard Deviation over time in single query

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

Range values in Tableau

I want to visualise the below excel table in Tableau.
When adding this table to Tableau it shows Salary values as String and thus under Dimension Tab and not under Measure, thus cannot make proper graph from it.
How to convert this Salary range values to Int ?
As #Alexandru Porumb suggested, the best solution is to have a min_salary column and a max_salary column — unless you really have the actual salary available which is even better.
If you don’t want to revise the incoming data, you can get the same effect using the Split() function in a calculated field from Tableau to derive two integer fields from the original string field.
For example, you could define a calculated field called min_salary as INT(SPLIT([Salary], ‘-‘, 1)). Split() extracts part of a string based on a separator string. Int() converts the string to an integer.
You could simplify the way it sees the data and separate the salary column into Min and Max, thus you wouldn't have the hyphen that makes Tableau consider the entry as a string.
Simplistic idea, I know but it may help until a better solution will be provided.
Hope it helps