SQL Cube-ISO 8601 Calendar insert 445 months - calendar

I'm quite new to SSAS and currently building a cube. Everthing is OK so fart except that I need to use the ISO 8601 Calendar but unfortunately the built-in doesn't contains the months but only year,week,day.
What I want to achieve is to add months with 445 patterns like reporting months but using weeks,days,start/end of year of ISO 8601 calendar.
Is it possible to achieve this without editing manually the calendar table?
Thanks
John

Exactly! I've finally done something using this kind of logic:
WHEN [ISO_8601_Week_Of_Year]>=1 AND [ISO_8601_Week_Of_Year]< 5 THEN 'January,'+REPLACE(ISO_8601_Year_Name,'ISO8601 Calendar','')
WHEN [ISO_8601_Week_Of_Year]>4 AND [ISO_8601_Week_Of_Year]< 9 THEN 'February,'+REPLACE(ISO_8601_Year_Name,'ISO8601 Calendar','')
WHEN [ISO_8601_Week_Of_Year]>8 AND [ISO_8601_Week_Of_Year]< 14 THEN 'March,'+REPLACE(ISO_8601_Year_Name,'ISO8601 Calendar','')
WHEN [ISO_8601_Week_Of_Year]>13 AND [ISO_8601_Week_Of_Year]< 18 THEN 'April,'+REPLACE(ISO_8601_Year_Name,'ISO8601 Calendar','')
WHEN [ISO_8601_Week_Of_Year]>17 AND [ISO_8601_Week_Of_Year]< 22 THEN 'May,'+REPLACE(ISO_8601_Year_Name,'ISO8601 Calendar','')
WHEN [ISO_8601_Week_Of_Year]>21 AND [ISO_8601_Week_Of_Year]< 27 THEN 'June,'+REPLACE(ISO_8601_Year_Name,'ISO8601 Calendar','')
WHEN [ISO_8601_Week_Of_Year]>26 AND [ISO_8601_Week_Of_Year]< 31 THEN 'July,'+REPLACE(ISO_8601_Year_Name,'ISO8601 Calendar','')
WHEN [ISO_8601_Week_Of_Year]>30 AND [ISO_8601_Week_Of_Year]< 35 THEN 'August,'+REPLACE(ISO_8601_Year_Name,'ISO8601 Calendar','')
WHEN [ISO_8601_Week_Of_Year]>34 AND [ISO_8601_Week_Of_Year]< 40 THEN 'September,'+REPLACE(ISO_8601_Year_Name,'ISO8601 Calendar','')
WHEN [ISO_8601_Week_Of_Year]>39 AND [ISO_8601_Week_Of_Year]< 44 THEN 'October,'+REPLACE(ISO_8601_Year_Name,'ISO8601 Calendar','')
WHEN [ISO_8601_Week_Of_Year]>43 AND [ISO_8601_Week_Of_Year]< 48 THEN 'November,'+REPLACE(ISO_8601_Year_Name,'ISO8601 Calendar','')
WHEN [ISO_8601_Week_Of_Year]>47 AND [ISO_8601_Week_Of_Year]<= 52 THEN 'December,'+REPLACE(ISO_8601_Year_Name,'ISO8601 Calendar','')
And then used another query like this:
SELECT MIN(ISO_8601_Week) AS 'Month_date',Month_Name
FROM [Reporting].[dbo].[SSAS_Calendar]
GROUP BY Month_Name
ORDER BY Month_date
Month_Name being the created column and Month_Date returned the beginning of each month.

You can add "Reporting Calendar" in Visual Studio. It can have 445 pattern. But for me it gives wrong numbers to weeks i.e. week gets the year of its Monday not its Thursday (as it should be according to ISO).
Choose "New dimension..." and then one of time dimension options.

Related

Create a running total in SQL with hours but only using work hours

This might be a strange question... but will try to explain the best i can ...
BTW : There is no chance in implementing through Stored Procedures... it should be made in SQL Query only ... But if the only option is SP, then i have to adapt to that ...
I have a table with the following elements :
RUN
WORKORDER
LOCATION
TRAVELTIME
NUMEQUIP
TOT_TIME
NO99
1
Start
NO99
2
Customer 1
112
1
8
NO99
3
Customer 2
18
11
88
NO99
4
Customer 3
22
93
744
NO99
5
Customer 4
34
3
24
I need to add a running DATE and HOUR by calculating the amount of time it takes from one line tho another BUT, and this is important, to take into consideration working hours ( from 9:00 to 13:00 and from 14:00 to 18:00 ( in US format : from 9am to 1pm, and 2pm to 6pm)... As example ... considering that my start date and time would be 10/May/2022 9:00 :
RUN
WORKORDER
LOCATION
TRAVELTIME
NUMEQUIP
TOT_TIME
DATE
TIME
NO99
1
Start
10/05/22
9:00
NO99
2
Customer 1
112
1
8
10/05/22
10:52
NO99
3
Customer 2
18
11
88
10/05/22
11:18
NO99
4
Customer 3
22
93
744
10/05/22
14:08
NO99
5
Customer 4
34
3
24
12/05/22
10:06
This result is achieved by calculating the estimated time to make the trip between customers (TRAVELTIME), and after arriving is also added the time spent on maintenance (TOT_TIME that is Number of Equipments (NUMEQUIP) vs 8 minutes per equipment)... By this, and since customer 3 will have 744 minutes (12 h and 58 minutes) in maintenance... and those minutes will spawn through 3 days, the result should be as shown...
With the following query i can have almost the desired effect... but cannot take into account only work hours ... and all time is continuous...
Select
RUN,WORKORDER,LOCATION,TRAVELTIME,
DateAdd(mi,temprunningtime-TOT_TIME,'9:00') As TIME,
NUMEQUIP,NUMEQUIP*8 AS TOT_TIME,sum(MYTABLE.TRAVELTIME +
MYTABLE.TOT_TIME) OVER (ORDER BY MYTABLE.ORDER) AS temprunningtime
FROM MYTABLE
With this query (slightly altered) i get an running TIME, but does not take into account the 13:00-14:00 stop, and the 18:00-9:00 stop...
It might be a bit confusing but any ideias on this would be very appreciated... and i will try to explain anyway i can...

SQL Query for Pagination

I have students data for their fees paid for each program, now I want to show the outstanding fees, now since it's possible student could have their outstanding fees for 2018, 2019 and 2020 pending, hence it will have 3 rows (The months will be in columns). Now since the student is same, I will be clubbing the records in the front end, now if I consider pagination and I have 10 per page limit, and in these 10 records 3 records is of the same student (since year was different), in that case I will end up having just 7 records on given page.
Here's the sample data.
Studentname RollNo Year Program Jan Feb Mar Apr May Jun ...
abc 1 2018 p1 200 50 10 30 88 29
abc 1 2019 p1 100 10 20 50 12 22
abc 1 2020 p1 30 77 33 27 99 100
xyz 2 2020 p2 88 29 32 99 199 200
How could I manage pagination for above case.
Assuming your front end is HTML/CSS/Javascript:
You don't need to handle pagination in your query - or even your backend - at all. Everything can and should be done on your frontend. I would suggest using JQuery and Bootstrap to create a paginated table to display your data using Material Design for Bootstrap

What SQL do I use to convert (big)datetime to show microseconds?

Sybase docs show how to convert to several date/time formats, but none show the microseconds that bigdatetime support. What CONVERT style can I use?
For instance:
SELECT CURRENT_BIGDATETIME()
-------------------
May 8 2019 4:30PM
^^^ I want microseconds here
I found several styles for which I could not find documentation, but they work for me, for instance,
SELECT CONVERT(CHAR(50),CURRENT_BIGDATETIME(),138)
May 8 2019 4:47:55.706489PM
Here are the styles I found and what their output looks like:
Style Output
36 4:34:28.070375PM
37 16:34:28.073989
38 May 8 19 4:34:28.077720PM
39 May 8 19 16:34:28.081418
40 19-05-08 16:35:41.892544
136 4:37:10.291454PM
137 16:37:10.295289
138 May 8 2019 4:37:10.299460PM
139 May 8 2019 16:37:10.304023
140 2019-05-08 16:37:10.308430
141 May 8 2019 4:37:10.312575PM
(this is on Adaptive Server Enterprise/15.7...)

Getting YTD figure in SSRS report with filtered column group on year/month

I have a Reporting Services report which shows a bunch of KPI scores. Each KPI has it's own Row on the report and for each row we show the SUM or AVG (depending on KPI type) score for last 3 years, and then a SUM, AVG or (ideally) total YTD figure per month in the current year:
KPI 2009 2010 2011 Jan Feb Mar Apr May etc.
Bagels Eaten (Total) 100 90 70 10 20 9 13 14
Sandwiches (Cumm. YTD) 90 75 86 13 23 46 65 76
The problem I'm seeing is that the RunningValue function appears to be working across rows, instead of within the filtered column group and current row that makes up the Jan, Feb, Mar columns (monthly data, grouped by year and month, filtered on current year). So the output is not as above, instead its a fairly random figure based on all the values in the rows (I'm sure it's not random it just looks like it is).
The Column Group is called "MonthNum" and the Expression for the cell value decides which aggregation to apply based on an "AggregationType" value in the source data:
=Switch(Fields!AggregationType.Value="SUM", Sum(Fields!ScoreValue.Value),
Fields!AggregationType.Value="AVG", Avg(Fields!ScoreValue.Value),
Fields!AggregationType.Value="YTD",
RunningValue(Fields!ScoreValue.Value,Sum,"MonthNum"))
Any help much appreciated
Update:
Here is an example few rows (scores per month, per kpi) of the data set being used (formatting is a bit tricky!). Items with aggragation type 'YTD' would have the cummulative YTD expression applied, everything else would be SUM for the current month:
KpiID Title KPIOwner ScoreValue YearNum MonthNum ReportingGroupTitle ScoreType DisplayOrder DisplayPrecision UnitOfMeasure AggregationType
5 Donuts Served Donut Manager 35 2007 1 Catering Services Actual 10020 0 Number YTD
5 Donuts Served Donut Manager 42 2007 2 Catering Services Actual 10020 0 Number YTD
5 Donuts Served Donut Manager 86 2007 3 Catering Services Actual 10020 0 Number YTD
5 Donuts Served Donut Manager 14 2007 4 Catering Services Actual 10020 0 Number YTD
6 Donuts Cooked Donut Manager 45 2007 1 Catering Services Actual 10020 0 Number SUM
6 Donuts Cooked Donut Manager 48 2007 2 Catering Services Actual 10020 0 Number SUM
6 Donuts Cooked Donut Manager 93 2007 3 Catering Services Actual 10020 0 Number SUM
6 Donuts Cooked Donut Manager 32 2007 4 Catering Services Actual 10020 0 Number SUM
6 Donuts Cooked Donut Manager 18 2007 5 Catering Services Actual 10020 0 Number SUM
From what I understand from your question this is what I would do:
Assuming that when the aggregation type YTD returns the acumulated totals until (and including) the MonthNum.
Create a Matrix with two a groups on KpiID and a child group on AggregationType, and two column groups (adjacent) one on the year and one on the month (on the year group, create a filter so that you don't include the current year and on the month group exclude the values where the year is not the current one).
Then you can use the following expression, for both the year and the month group (the last will give you the YTD value for the last month in each year)
=Switch(Fields!AggregationType.Value="SUM", Sum(Fields!ScoreValue.Value),
Fields!AggregationType.Value="AVG", Avg(Fields!ScoreValue.Value),
Fields!AggregationType.Value="YTD", Last(Fields!ScoreValue.Value))

Hive Query - Pivot Table by First and Last Entry of Date

To start here is some sample data
Sample Input
ID Date Value
10 2012-06-01 00:01:45 20
10 2012-06-01 00:01:51 12
10 2012-06-01 00:01:56 21
10 2012-06-01 00:02:01 43
10 2012-06-01 00:02:06 12
17 2012-06-01 00:02:43 64
17 2012-06-01 00:02:47 53
17 2012-06-01 00:02:52 23
17 2012-06-01 00:02:58 45
17 2012-06-01 00:03:03 34
Desired Output
ID Date
10 2012-06-01 00:01:45 2012-06-01 00:02:06 20 12
17 2012-06-01 00:02:43 2012-06-01 00:03:03 64 34
So I am looking to get the first and last date, and values for both into a single line. The ID value in my table will also have other entries at later dates, so I only want to get the first and last for a chain of entries. Each entry is 5 secs apart. If they are greater then that it is a new chain.
Any suggestions?
Thanks
I'm just beginning the search process on this but it looks like LATERAL VIEW and EXPLODE coupled with maybe a user defined function or two are your friend.
I ended up creating a MapReduce job to work on the csv files of my data instead of using hive.
I "mapped" based on ID. Then set a parameter where if data's were further then 2 hours I separated them.
In the end it was easily to hack the MapReduce code then ponder hive queries.

Resources