Power Query Calendar - calendar

I am trying to create a calendar using Power Query functions and for that I used below syntax in blank query:
Source= Duration.TotalDays(DateTime.LocalNow() - #datetime(2014,01,01,00,00,00)) * 24
Date= List.DateTimes(#datetime(2014,01,01,00,00,00), Source ,#duration(0,1,0,0))
Then I convert to a table and apply query.
Connect dimension date table to date column in fact table.
 
The error occurs when I’m trying to mark table as date table:
‘The date column can only gave one timestamp per day. The date column
can’t have gaps in dates’
 
What I have done wrong?

As the error message says:
The date column can only have one timestamp per day.
While you are trying to add 24, one for each hour. See the requirements for setting a table as a date table:
if it is a Date/Time data type, it has the same timestamp across each value
i.e. you can have only one value for each date, and if it is not a date, but datetime value, all time values should be the same.

Related

T-SQL MIN on Date type resulting in INT

I have a table with a column called ThisDayOfTherapy which is of datatype DATE in SQL Server.
Later, I have an aggregate query using Min(ThisDayOftherapy). This query populates a #temp table with the result of Min(ThisDayOfTherapy) as column name StartDate_Min
In a 3rd location I am finally doing something with StartDate_Min. When I hold my mouse over StartDate_Min, it says the datatype is INT.
Shouldn't it simply be DATE? Will it still work as if it were a date for all practical purposes?
I see the same behavior, but I think you will be fine. SQL Server would not execute any date functions if it was not a valid date. Adding one day to my MinDate column from my temp table is working as expected.

KDB Select from partitioned table where date is less than a given date - 1 day

I would like to select from a partitioned table where the date is the highest date strictly below a given date d.
I can do the following:
d:2019.10.02;
{select from x where date = max date} select from t where date < d
where t is my partitioned table.
The issue with the above query is that it is very slow as it has to first load all the dates strictly older than d, and then taking the max date out of it.
To select all the dates that are earlier than your specified date you can use the select statement below:
select from t where date=max date where date<d
Where t is your partitioned table and d is your specified date.
If you just want to select from the max date in a date partitioned hdb
Lets assume that the max populated date partition less than 2019.08.20 is 2019.08.07
q)d:2019.08.20
q)select from t where date=max date where date<d
This is because the partition type is available as a variable once you load into a DB, (i.e,. date, month, int etc). This will be the .Q.pf variable.
select from table where date=(last .Q.pv where .Q.pv < d)
kdb+ stores a variable in memory which contains all the dates within your db.
select from telemetry where date=desc[date]1
Above where clause will sort this by largest ->smallest
Selecting index 1 will filter the max date out of your query (without first querying the entire dataset).

Add wrapper on date columns in SQL server

I have DB with tables having datetime columns.
Can I add wrapper over those dateTime columns which I can activate/deactivate as per my need, so that all date time converted to a specific Timezone before retrieval.
e.g. I have a Table ABC with column ExpDate having value '12-10-2019 2:30'
When I execute
select * from ExpDate
then it will result
'12-09-2019 19:30' (after converting it from UTC to PST(UTC-7))
I want this solution be generic so that it get implemented for all dataTime column in all tables.

SSRS date/time parameter

I have a ssrs report that has a date/time parameter that allows the user to select the date when running report. how to I get it to exclude the time part of the date field.
currently the field in the db is a date/time field so when I run query
select count(*) from table where date <= #dateparameter
it is not including records where the time part of field is greater than 00.00.00
how can I ignore the time part so all records are returned for that date
The simplest (and probably best performance) solution would be to add a day to the date passed by the user amd change the <= to <:
select count(*) from table where date < DATEADD(DAY, 1, #dateparameter)

Date and Time in SQL Developer

I have 2 tables, 1 table has a date column, 1 table has a time column. I want to have date and time works seperatedly. This is what i use :
ALTER SESSION SET nls_date_format='dd/mm/yyyy';
I use this for the 1st table and then use this for the 2nd table :
ALTER SESSION SET nls_date_format='hh24:mi';
But it doesn't work right. When i do the select * from it all changes back to hh24:mi type. How can i have date and time seperatedly ?
As noted Oracle always has a date and time. If you want to see and use just the date or just the time you could use, for example to only work with the time, TO_CHAR(ColumnA, 'HH24:MI:SS')

Resources