Alias Dimension member value in SSAS - ssas

Is it possible to display or return a different value for an attribute in SSAS?
For example, in my date dimension I derive the business day within the month. Something like this:
DateId Date BusinessDay WeekDay
20120101 2012-01-01 01 Mon
20120102 2012-01-02 02 Tue
20120103 2012-01-03 03 Wed
20120104 2012-01-04 04 Thu
20120105 2012-01-05 05 Fri
20120106 2012-01-06 05 Sat
20120107 2012-01-07 05 Sun
02120108 2012-01-08 06 Mon
But the problem is every month has a 01 BusinessDay in it, so when I am creating a hierarchy for this, I get an error for duplicates. Also on the weekends I keep the business day constant.
So I need a way to have a unique BusinessDay value, but show a user friendly value. I was thinking I could concatenate the DateId + BusinessDay, but with an expression only show the Right 2 characters.
Making 2012010101 display as 01
Is this even possible? Maybe in the attributes properties somewhere?

I was able to accomplish this by doing the following:
I added two columns to the DSV. One for the value to be displayed, and a second for the true value. Next, I opened the Design view of the date dimension and added the attribute relationship just like adding any new attribute.
Now to make this work you have to open the attribute properties. and scroll all the way to the bottom and under the Source options update the KeyColumns to the actual value attribute. Next, in the same Source Options, update the NameColumn to the Display value you want.
It's actually pretty easy.

Related

MDX Calculated Measure Year to Date

I have an OLAP multi dimensional cube, which in its simplest form contains:
A fact table with a NetAmount measure
A Time dimension, with fields for Year, Month, Day, Day of Month, Day of Year, etc
The requirement is that the user wants to be able to compare the total NetAmount from the beginning of each year up to a specific date. The date can be chosen by setting filters on the Day and Month fields. For example, the user wants to see total value for:
01 Jan 2019 to 20 Jan 2019
01 Jan 2018 to 20 Jan 2018
01 Jan 2017 to 20 Jan 2017
etc
What would be the best way to tackle this requirement?
You can create calculated member with YTD function like this:
CREATE MEMBER CURRENTCUBE.[Measures].[NetAmountYTD]
as
Aggregate(YTD ([Time].[Time].CurrentMember), [Measures].[NetAmount])
You could also create Utility dimension for example TimeUtility, and add YTD member, and define it like this:
Scope([TimeUtility].[YTD]);
this = Aggregate(YTD ([Time].[Time].CurrentMember), [TimeUtility].[DefaultMember]);
End Scope;
This way whatever measure you look against [TimeUtility].[YTD] it will give you Year to Date for that measure, not just NetAmount, so it will be general solution.

T-SQL: August is the beginning of next years financial year, code to dynamically to change the batch ids

I have a column called batch_id with a list of dates - 2016080184 ie date 2016 08 01 84(84, I believe a time part).
I need to update the batch_id (varchar(25)) to change to 2017010184, based on another column voucher_date (datetime) = 2016-08-01 00:00:00.000
So if the voucher date was 2016-08-02 00:00:00.000, then the batch_id needs to change from 2016080278 to 2017010278 (78 at the end here doesn't matter)
August is the first month for the financial year, so August would effectively become January, September would become February etc.. and the year from Aug needs to indicate the following year ie this year is 2016 therefore batch_id should start with 2017.
Next August batch_id should indicate 2018 etc..
The file I receive is always a day behind to make things more complicated.
I am a little confused about your requirement for the year to change, but this should give you all you need to get started:
declare #BatchID nvarchar(10) = '2016080184'
select convert(nvarchar(8),dateadd(month,-7,cast(left(#BatchID,8) as date)),112) + right(#BatchID,2) as NewBatchID_SameYear
,convert(nvarchar(8),dateadd(month,5,cast(left(#BatchID,8) as date)),112) + right(#BatchID,2) as NewBatchID_NextYear
You can apply the above date changes with a CASE statement on the voucher_date column as required.

Interval Based Report Sql Server

I need First Login and Last Logout report for CC agents, I have information of every login and logout they perform during their shift (i.e Logout for lunch/smoke/breaktime etc).
We have the Following shifts:
S.No Shift Possible Login Possible Log Out
1. 08 – 04 8: 07 16:05
2. 10 – 06 10:03 18:09
3. 04 – 00 16:08 00:02
4. 06 – 02 18:04 02:01
5. 00 – 08 23:57 08:04
I have this view for collecting relevant information as below:
Problem with this report is that if I am generating a single day report as 20/06/2016 then I am not able to capture information on Shift S.No. (3,4,5) because there is a day change.
For Example:
Agent Login Date/Time is: 20/06/2016 18:10
And
Agent Logout Date/Time is: 21/06/2016 02:05
I need something like to have Interval column where day starts at 20/06/2016 03:00 and day ends at 21/06/2016 03:00 how to achieve this Interval ? Or if you have any other Idea for this report requirement.
If I understood you correctly, based on the view you've shown there, you need to provide data for all the people that were working on, say, 20/06/2016? If that's so, I believe you could select from the view all the people whose
CAST(FirstLogin AS date) = '20160620'
If you needed to also include the people who started working on 19/06/2016 and ended on 20/06/2016 then you would do the same for LastLogOut.
In addition, if you were to write it as a dynamic query, if you needed to provide a report for yesterday for example, you'd substitute the 20/06/2016 from the where clause with
CAST(DATEADD(day, -1, GETDATE()) AS date)

Sorting records based on modified timestamp?

I am trying to sort a list of records that have been created using a screen scraping script. The script adds the following style of date and time (timestamp) to each record:
13 Jan 14:49
The script runs every 15 minutes, but if I set the sort order to 'time DESC' it doesn't really make sense because it lists the records as follows:
13 Jan 14:49
13 Jan 12:32
13 Jan 09:45
08 Feb 01:10
07 Feb 23:31
07 Feb 06:53
06 Feb 23:15
As you can see, it's listing the first figure correctly (the day of the month in number form) but it's putting February after January. To add to the confusion it's putting the latest date in February at the top of the February section.
Is there a better way of sorting these so they are in a more understandable order?
If you are storing the values in a database, simply use the column type datetime when creating the field. The database will treat the field as time and will sort the values chronologically.
Otherwise, if you are storing the values elsewhere, for example in a flat file, convert the formatted time to unix time. Unix time is an integer, thus you can sort it easier.
Time.parse("13 Jan 09:45").to_i
# => 1326444300
Time.parse("08 Feb 01:10").to_i
# => 1328659800
You can always convert a unix time to a Time instance.
Time.at(1328659800).to_s
# => "2012-02-08 01:10:00 +0100"

Conditional formating based date range in VB

Have a column of dates which i need to compare to a specific time of the year, which establishes what calculation needs to be applyed then depending on the outcome apply conditional formating to highlight an adjcent cell, but need to remove the YY element as the contents spans multiple years.
if the date in A1 is between 1st Jan & 14th Mar use -8
if the date in A1 is between 15th Mar & 15th Oct use -17
if the date in A1 is between 16th Oct & 31st Dec use -8
Then deduct the above value from B1 to give a target
for each row (from 3 onwards)
if the target is < the value in n then change background orange in f
and repeat.
Any help would be greatly welcome, thank you.
Is this Excel? If so, then it has all kinds of conditional formatting stuff built right into the application; no programming needed.