How to validate date field in Azure Data Factory Mapping Flows in Conditional split operator - azure

Source date fields coming to my flow looks like a regular date in YYYY-MM-DD format. I'd like to use Conditional split operator to validate if a particular column can be converted to date column.
I was trying to use something like this:
isNull(toDate($column_list[3])) == false()
But it does not work as expected -> it rejects every single row....
Can you help?

Per my experience, if the coming data(we consider it's a string data in default) is not a valid date string, the result of toDate() function will return NULL.
Ref this example:
As you said , the coming data are regular date in YYYY-MM-DD format, it's a valid date data(string) and that will cause the expression isNull(toDate($column_list[3])) always return false(not null), then false()==false() also will always return true.
The expression will always return true, that why it doesn't work ad expected.

Related

Recognize date format '14-August-2020 12:30:42' as type datetime

I'm trying to convert a datetime column in format '2020/08/14 12:30:42' to a datetime column with format '14-August-2020 12:30:42' using the following function:
select
*,
date_format(starttimecet,'%d-%M-%Y %h:%i:%s) as test
from table
While this function in successful in doing that, the '14-August-2020 12:30:42' format of the test column no longer recognizes it as a datetime column. Is there a way to have a column in this format but still have it recognized as type datetime?
No, once you convert your bona fide datetime literal into a text string, it is no longer datetime. Your current query is actually along the lines of what you should be doing in general. Specifically, you should keep the original datetime column throughout your query as needed, and then display the text you want in the final outer select.

concatenate string with date in SAS eg

I need to create a computed column in SAS with the combination of the string 'ULPDT_' and the result from the today() function. so that my result looks like this: ULPDT_20190101. Here is my non-functional code for the advanced expression:
t1.SourceFile='ULPDT_'||PUT(today(), yyddmmn8.)
year-day-month, YYYYDDMM, is not a normal representation for date, you might actually want year-month-day YYYYMMDD
t1 is indicative of an EG generated join wherein the t1 is a table alias. If you are editing the code of a join node, and the problematic statement is part of a select clause, the correct SQL syntax might be
'ULPDT_'||PUT(today(), yymmddn8.) as t1.SourceFile
Hand coded example (versus EG visual join):
proc sql;
create table x as
select
'ULPDT_'||PUT(today(), yymmddn8.) as SourceFile
from
sashelp.class(obs=1)
;

Excel Power Query - from web with dynamic worksheet cell value

We have a spreadsheet that gets updated monthly, which queries some data from our server.
The query url looks like this:
http://example.com/?2016-01-31
The returned data is in a json format, like below:
{"CID":"1160","date":"2016-01-31","rate":{"USD":1.22}}
We only need the value of 1.22 from the above and I can get that inserted into the worksheet with no problem.
My questions:
1. How to use a cell value [contain the date] to pass the date parameter [2016-01-31] in the query and displays the result in the cell next to it.
2. There's a long list of dates in a column, can this query be filled down automatically per each date?
3. When I load the query result to the worksheet, it always load in pairs. [taking up two cells, one says "Value", the other contains the value which is "1.22" in my case]. Ideally I would only need "1.22", not the title, can this be removed? [Del won't work, will give you a "Column 1" instead, or you have to hide the entire row which will mess up with the layout].
I know this is a lot to ask but I've tried a lot of search and reading in the last few days and I have to say the M language beats me.
Thanks in advance.
Convert your Web.Contents() request into a function:
let
myFunct = ( param as date ) => let
x = Web.Contents(.... & Date.ToText(date) & ....)
in
x
in
myFunct
Reference your data request function from a new query, include any transformations you need (in this case JSON.Document, table expansions, remove extraneous data. Feel free to delete all the extra data here, including columns that just contain the label 'value'.
(assuming your table of domain values already exists) add a custom column like
=Expand(myFunct( [someparameter] ))
edit: got home and got into my bookmarks. Here is a more detailed reference for what you are looking to do: http://datachix.com/2014/05/22/power-query-functions-some-scenarios/
For a table - Add column where you get data and parse JSON
let
tt=#table(
{"date"},{
{"2017-01-01"},
{"2017-01-02"},
{"2017-01-03"}
}),
add_col = Table.AddColumn(tt, "USD", each Json.Document(Web.Contents("http://example.com/?date="&[date]))[rate][USD])
in
add_col
If you need only one value
Json.Document(Web.Contents("http://example.com/?date="&YOUR_DATE_STRING))[rate][USD]

Date arithmetic in Cognos 8

What I need is a data item expression which outputs the starting date of the current quarter of last year. Finding the current year is easy, as is subtracting 1 year from that date. But beyond that I get stuck.
I currently have an ugly if expression for each quarter like:
if (extract(month,current_date) in (10,12,12))
then ((extract(year,_add_years (current_date,-1))||'-10-01'))
But no matter what I do I can't concatonate the year and date into string I can convert to a date object. The above code gives the error:
The operation "add" is invalid for the following combination of data types: "integer" and "character"
Trying to cast the integer as a character using cast() I get this error. I also get this error when trying to turn a character array into a date:
The operation "condexp" is invalid for the following combination of data types: "character" and "integer"
Trying to use SQL Server specific functions (it is a SQL Server database) just gives me an error that those functions are unavailable for local processing, so I can't seem to use SS date arithmatic, and I can't find anything particularly applicable in Cognos' built in date functions.
How can I manipulate a date to add a year to a known day/month combination and use that as a date object?
I'm using cognos 10.1.1, but it would work.
You can get the value by using the following code:
_make_timestamp(
extract(year, _add_years(current_date, -1)),
(floor((extract(month,current_date)-1)/3)*3+1),
01
)
The following is the simple way to get the starting month of the quarter.
(floor((extract(month,current_date)-1)/3)*3+1),
and you can convert timestamp to date or string.
cast(
_make_timestamp(
extract(year, _add_years(current_date, -1)),
(floor((extract(month,current_date)-1)/3)*3+1),
01
),
date
)
,
cast(
cast(
_make_timestamp(
extract(year, _add_years(current_date, -1)),
(floor((extract(month,current_date)-1)/3)*3+1),
01
),
date),
varchar(10)
)
plus, you can use extract function when you get a day value.
extract(day, _first_of_month (current_date))
I would go with SQLSERVER built-in functions tht exists in Cognos.
Here is an expression that works for me:
DATEADD({month},(3)*((DATEPART({quarter},[FullDateAlternateKey]))-1),
DATEADD({YEAR}, DATEDIFF({YEAR}, 0, dateadd({year},-1,[FullDateAlternateKey])), 0))
The FullDateAlternateKey field is my date field (from ADVERTUREWORKS DW DB).
If you still have problems, try to isolate the problem by trying this expression on new simple list report.

How to compare just the date, not the timestamp using LINQ

I'm trying to compare just the date of a column but because the query below is also comparing the time I get no result set back.
How could I write this same LINQ query if I'm only interested in the actual date value matching?
The column "ImportDate" has a value that looks similar to this 2009-08-30 12:26:00
from t in UnitsOfWork _
where t.ImportDate = "08/30/2009" _
select t
You can compare it as a string or you can use just the Date property on ImportDate
where t.ImportDate.ToString("yyyyMMdd") == "20090830"
or
where t.ImportDate.Date == new DateTime(2009,8,30)

Resources