I have a static calendar hierarchy in SSAS Tabular model with minutes, hours, days. This way I can do cool metric grouping by dates like:
2017-01-01 45
2017-01-02 3
2017-01-03 17
I want to be able to do groupings by work shifts which are no more then 24 hours long. I could extend my calendar hierarchy with static shifts. But I need work shifts to be user definable on the fly.
For example user can set 22-hour shift from 03:00 to 01:00.
What approach should I take to include dynamic shifts into calendar hierarchy?
Related
I have a data for a period from December 2013 to November 2018. I converted it into a data frame as shown here.
Date 0.1 0.2 0.3 0.4 0.5 0.6
2013-12-01 301.04 297.4 296.63 295.76 295.25 295.25
2013-12-04 297.96 297.15 296.25 295.25 294.43 293.45
2013-12-05 298.4 297.61 296.65 295.81 294.75 293.89
2013-12-08 298.82 297.95 297.15 296.25 295.45 294.41
2013-12-09 298.65 297.65 296.95 296.02 295.13 294.05
2013-12-12 299.05 297.33 296.65 295.81 294.85 293.85
2013-12-16 301.05 300.28 299.38 298.45 297.65 296.51
....
2014-01-10 301.65 297.45 296.46 295.52 294.65 293.56
2014-01-11 301.99 298.95 298.39 297.15 296.05 295.11
2014-01-12 299.86 298.65 297.73 296.82 296.35 295.37
2014-01-13 299.25 298.15 297.3 296.43 295.26 294.31
I want to take monthly mean and seasonal mean of this data.
For monthly mean I have tried
df.resample('M').mean()
And it worked well.
For seasons, I would like decompose this data into 4 seasons (December-Feb; Mar-May; June-Aug; and Sep-Nov) of three months interval. While I tried the resample with 3 months interval. i.e.
df.resample('3M').mean()
However this is not worked well as it giving the average for the starting December month separately and then considering the above said interval for a calendar year (ie. from January to March and so on).
I would like to know if there are any possible ways to avoid this by specifying which month is our period of consideration begins.
Moreover, I would also like to know whether we can define these seasons beforehand and group the data accordingly to get averages with more ease.
You can define the origin in resample:
df.resample('M', origin=pd.Timestamp('2013-12-01')).mean()
is it possible to have date_diff with specific start and end time?
let say my store are open from 8AM - 10PM, which is 14 Hours.
and I have a lot of stuff to sell during that time. One of the SKU is out of stock from 2022-11-01 06.00 PM until tomorrow 2022-11-02 11.00 AM.
Instead of calculate 24 hours, I just want to calculate only from opening store until it closed or until its restock. Meaning from 6PM to 11AM is 8 Hours
my query
select date_diff('2022-11-02 11.00 AM', '2022-11-02 06.00 PM', hour) from table
with the result 17 hours instead of 8 hours
There isn't a way to configure DATE_DIFF to do this for you, but it's possible to do what you want, with some effort.
You should convert your dates to timestamps (TIMESTAMP(yourdate) or CAST(yourdate AS TIMESTAMP)) and use TIMESTAMP_DIFF instead.
This will allow you to work with smaller intervals than days.
For your calculation, you ultimately need to find the total time difference between the two timestamps and then subtract the out-of-hours timeframe.
However, calculating the latter is not as simple as taking the difference in days and multiplying by 8 hours (10pm-6am), because your out-of-hours calculation has to account for weekends and possibly holidays etc. Hence it can get quite complex, which is where the solution in my first link might come in.
I'm using Prophet (Python) to predict and analysis time series in bulk. that means that my time series share the same properties, but they are not exactly the same. They all run from 2016-01-01 to 2020-Jul-01.
I would like to cross validate my results using the first 3 years of data, and my forecast goal is 15 days only.
What is the best configuration to test my fit using the first 3 years, aiming for a 15 days forecast?
My naive try is the one below:
df_cv = cross_validation(mts, initial="1095 days", period='31 days', horizon = '15 days')
I'm not sure what to add in the 'period' and in the 'horizon' parameters.
As mentioned in Prophet's documentation:
We specify the forecast horizon (horizon), and then optionally the size of the initial training period (initial) and the spacing between cutoff dates (period).
Thus, a forecast is made for every observed point between cutoff and cutoff + horizon.
So, you can specify any combination of the 'period' and in the 'horizon' parameters as long as their sum is equal to the period for which you want to forecast (15 days).
I have the following situation in my cube:
Shop A uses calendar Cal1. Their sales month starts Jan 5th.
Shop B uses calendar Cal2. Their sales month starts Jan 10th.
Shop C...etc
Shop calendars can not simply be represented as offsets of a main calendar. They have different working days, public holidays etc.
I need to produce a daily (reporting services) report with the actual calendar date as a parameter. The list of shops is also a multi select parameter. If a user selects the 15th of Jan, I need to show the combined MTD sales for all shops selected in the parameters. So that would mean the first 10 days of sales for shop A and the first 5 days of sales for shop B etc.
Any ideas how I can make this work? I'll also need to provide YTD figures in the same manner.
I am implementing multiple calendars using a bridging table between my date and calendar dimensions. It is the technique described here: http://duncansutcliffe.wordpress.com/2010/06/11/a-better-date-dimension/
I can not hard code the calendars as there is a requirement to possibly add more in the future without modifying the schema.
I am not sure I understand you sales data start days, but if I do then the solution is to make an extra dimension as a "reporting calendar" as a point of harmony between the actual calendars
Each shop has a known offset to the reporting calendar, so for shop A it's 5 days, for shop B it's 10 days etc
When you add fact data you also need to calculate a reporting date using the offset. So for Shop A 5 Jan is actually 1 Jan etc
When reporting, the user selects a date on the reporting calendar, and facts are selected based on that
e.g. if the user selected reporting calendar 15th Jan, it would only select actual dates 1 to 15 Jan and reporting calendar up to 15 and only Jan
Data selected would be Shop A 5 to 15, Shop B 10 to 15
1 to 4 Jan for Shop A and 1 to 9 for Shop B would be in Dec of the reporting calendar, and not included because of the filter of reporting calendar Jan
i have a table called DrTimings ,in which Doctors time for each day is this.
DrID(int identity) StartTime(DateTime) EndTime(DateTime)
1 3/31/2009 8:00:00 AM 3/31/2009 10:30:00 AM
I have another table called TimeList which contain 3 fields
SlotID SlotStartTime(varchar) SlotEndTime(varchar)
1 8:00AM 8:15AM
2 8:15AM 8:30AM
3 8:30AM 8:45AM
and goes on till 7:00PM
I have another table DrDutyDetails in which DrTiming is set for whole month like this.
DrID StartTime EndTime DateOfAllocation
1 4/5/2009 8:00:00 AM 4/5/2009 9:30:00 AM 4/5/2009 12:00:00 AM
2 4/12/2009 8:00:00 AM 4/12/2009 9:30:00 AM 4/12/2009 12:00:00 AM
likewise
I have another table called AppointmentSchedule which gets filled when patient requests appointment
AppointmentID SlotID AppointmentDate
1 1 4/5/2009
2 3 4/12/2009
i have a appointment schedule form in which i selects DrID and Appointment date.Then slots corresponding to date that has not been in Appointmentschedule,but slots should be in between starttime and endtime that in DrTimings and in TimeSlots should get filled in a dropdownlist.I need a query to implement this.
for eg:If Patient enters '4/5/2009' Then slots other than 1 and 3 but biw DrTimings i want to get.
Similarly i want to search by time.Means if Patient enters any time b/w DrTimings for eg:8:30AM,Then available first date has to be displayed in textbox
You are going to need to look at doing some Casting/COnverting of date values. This MSDN article gives you a bit of information on what you need to work with.
There are a number of ways that you can do this, but ideally you can do something like CONVERT(VARCHAR(50), StartTime) to get the fully formatted time. Then, since you know that the ending format of that is 08:00AM, you can do a RIGHT(CONVERT(VARCHAR(50), StartTime), 7), which will get you just the time value.
Now, with that you know how to manipulate the date into parts, you can from here, do the various things needed to query your items.
For comparison sake, I would be storing the "TimeList" data as DateTime values, that way you can use standard time comparisons to actually allow you to use functions such as "Between" and similar. You could store them as 1/1/1900 08:00AM or similar. But this would require a data model change. If you want some helpful SQL for this type of thing, here is a great article on "Essential SQL Server Date, Time, and DateTime Functions".