Grouping attributes in SSAS - ssas

I have an account dimension where the same account can have multiple account numbers. So I setup a durable key to group these accounts. So for example
Durablekey AccountNum
1 1
1 2
1 3
2 4
3 5
The durablekey has no business meaning. I would like to have an attribute in cube that displays the accountnum but would essentially have the durablekey as the key. So if I selected accountnum 2 it would pull all the information for everything with a durablekey of 1. If I simply set the accountnum as the name and durablekey as the key I get a duplicate error during processing as expected.
Is this possible to do?

Hi there is sample data http://msftdbprodsamples.codeplex.com/releases/view/55330
You need to make Parent->Child Hierarchie, that Account key was normal integer key and other Accounts will have Parent Account key, which show to Parent Account. Parrent Account can have multiple other Accounts:
AccountKey | ParentAccount | Code
1 - 102
2 1 10255
3 1 10266
4 3 13444
5 3 13555
There is a lot of examples in internet just type - SSAS Parent - Child :
http://my.safaribooksonline.com/book/databases/microsoft-sql-server/9780735626201/creating-dimensions/creating_a_parent-child_dimension
Also you can use sample database and SSAS projects, there is everything done on working Cube...

Related

relational link within one table

I have Table User, which consists of two columns - id_user and name_user?
id_user
name_user
1
Vova
2
John
3
Ivan
4
Kate
I need to make relation between two users. If I understood correctly I should make Table relation_ids:
id_user_1
id_user_2
1
2
1
3
1
4
2
3
Tell me please do I need to double relationships between two users (for example 1-2 and 2-1)? Is there another ways to make relation within one table?

How to Normalize a table where a column references multiple rows of a different column in the same table

I am trying to create a table that lists different applications and if they integrate with other applications on that list.
ID SKU NAME Integrations
1 pdk1 hubspot crm pdk3,pdk4,pdk5
2 pdk2 sugar crm pdk5
3 pdk3 pipedrive pdk1
4 pdk4 quickbooks pdk1
5 pdk5 mailchimp pdk1,pdk2
How can I normalize the integrations column?
The relations between SKUs in your example are "many-to-many" (M:M). Storing multiple comma-separated values in the column violates the first normal form (1NF). Hence you need normalise table and model M:M relation using an additional link table.
SKU table
SKU
---
ID SKU NAME
1 pdk1 hubspot crm
2 pdk2 sugar crm
3 pdk3 pipedrive
4 pdk4 quickbooks
5 pdk5 mailchimp
Link table
SKU_INTEGRATION
---------------
ID INTEGRATED_WITH_ID
1 3
1 4
1 5
2 5
3 1
4 1
5 1
5 2
You may have a look on the book "Programming with databases" which covers the topics of normalization, modeling of different types of links etc.
Is this what you want?
select id, sku, name,
regexp_split_to_table(integrations) as integration
from t;
This isn't exactly "normalized" but it removes the use of a delimited string to represent multiple values.

SQL - Tracking student exam records as they move between schools

I'd like to pick some of your glorious minds for an optimal solution to my dilemma.
Scenario:
Schools have children and children take tests.
The tests point to the child, not the school.
If the child moves school, the test records are taken to the new school and the previous school has no record of the test being done as they are linked to the child.
Obviously, this isn't ideal and is the result of the database not being designed with this in mind. What would the correct course of action be; I’ve currently identified the 3 possibilities listed below which would solve the current problem. However, i cannot be sure which is best for the issue at hand - and if any better solutions exist.
Have each test store the school & student within the test records (requiring current records to be updated & increasing the size of the database)
Create a new child record, duplicating the existing data for the new school with a new ID so the test remains linked to the previous school (complicating the ability to identify previous test scores)
Separately keep track of moves to other schools, then use this additional table to identify current and previous using the timestamps (increased complexity and computational requirements)
EDIT:
So i tried to use a basic example, but requests for the task at hand have been requested.
Here's the DB Schema for the tables (simplified for problem, note: Postnatal is not important):
Patients: ID, MidwifeID, TeamID
Midwives: ID
Groups: ID
GroupsMidwives: MidwifeID, GroupsID
PatientObservations: ID, MidwifeID, PatientID
Using a query as follows:
SELECT Some Information
from Postnatals
JOIN Midwives on Postnatals.MidwifeID = Midwives.ID
JOIN Patients on Patients.PatientID = Postnatals.PatientID
JOIN GroupsMidwives on GroupsMidwives.MidwifeID = Midwives.ID
JOIN Groups on Groups.ID = GroupsMidwives.GroupID
JOIN PatientObservations on PatientObservations.PatientID =
Postnatals.PatientID
WHERE groups.Name = ?
*some extra checks*
GROUP BY Midwives.Firstname, Midwives.Surname, Midwives.ID
However, in the event that a midwife is moved to a different team, the data associated with the previous team is now owned by the newly assigned team. As described in the example detailed previously.
Thus a modification (which modification is yet to be realised) is required to make the data submitted - prior to a team change - assigned to the previous team, as of current, because of the way the records are owned by the midwife, this is not possible.
You should below suggestion as per you concern.
Step 1 ) You need to create School Master Table
ID | School | IsActive
1 | ABC | 1
2 | XYZ | 1
Step 2 ) You need to create Children Master having school id as foreign key
ID | School | Children Name| IsActive
1 | 2 | Mak | 1
2 | 2 | Jak | 1
Step 3 ) You need to create test table having children id as foreign key
ID | Children_id | Test Name | IsActive
1 | 2 | Math | 1
2 | 2 | Eng | 1
Now whenever child moves school then make child record inactive and create another active record with new school. This will help you to bifurcate the old test and new test.
do let me know in case morehelp required

Check if a value exists in the child-parent tree

I'm creating a simple directory listing page where you can specify what kind of thing you want to list in the directory e.g. a person or a company.
Each user has an UserTypeID and there is a dbo.UserType lookup table. The dbo.UserType lookup table is like this:
UserTypeID | UserTypeParentID | Name
1 NULL Person
2 NULL Company
3 2 IT
4 3 Accounting Software
In the dbo.Users table we have records like this:
UserID | UserTypeID | Name
1 1 Jenny Smith
2 1 Malcolm Brown
3 2 Wall Mart
4 3 Microsoft
5 4 Sage
My SQL (so far) is very simple: (excuse the pseudo-code style)
DECLARE #UserTypeID int
SELECT
*
FROM
dbo.Users u
INNER JOIN
dbo.UserType ut
WHERE
ut.UserTypeID = #UserTypeID
The problem is here is that when people want to search for companies they will enter in '2' as the UserTypeID. But both Microsoft and Sage won't show up because their UserTypeIDs are 3 and 4 respectively. But its the final UserTypeParentID which tells me that they're both Companies.
How could I rewrite the SQL to ask it to return to return records where the UserTypeID = #UserTypeID or where its final UserTypeParentID is also equal to #UserTypeID. Or am I going about this the wrong way?
Schema Change
I would suggest you to break it down this schema a little bit more, to make your queries and life simpler, with this current schema you will end up writing a recursive query every time you want to get simplest data from your Users table, and trust me you dont want to do this to yourself.
I would break down this schema of these tables as follow:
dbo.Users
UserID | UserName
1 | Jenny
2 | Microsoft
3 | Sage
dbo.UserTypes_Type
TypeID | TypeName
1 | Person
2 | IT
3 | Compnay
4 | Accounting Software
dbo.UserTypes
UserID | TypeID
1 | 1
2 | 2
2 | 3
3 | 2
3 | 3
3 | 4
You say that you are "creating" this - excellent because you have the opportunity to reconsider your whole approach.
Dealing with hierarchical data in a relational database is problematic because it is not designed for it - the model you choose to represent it will have a huge impact on the performance and ease of construction of your queries.
You have opted for an Adjacently List model which is great for inserts (and deletes) but a bugger for selects because the query has to effectively reconstruct the hierarchy path. By the way an Adjacency List is the model almost everyone goes for on their first attempt.
Everything is a trade off so you should decide what queries will be most common - selects (and updates) or inserts (and deletes). See this question for starters. Also, since SQL Server 2008, there is a native HeirachyID datatype (see this) which may be of assistance.
Of course, you could store your data in an XML file (in SQL Server or not) which is designed for hierarchical data.

Getting all the rows even though they are not mapped in Dimension usage

I have a fact table that can store 2 types of transactions - TrxType1, TrxType2 having an attribute called Owner_Id mapped to Dim Owner. Problem is only one type of transaction TrxType1 has owner and the other does not have a relationship. Hence while querying the cube I am not getting the records for TrxType2.
Is there a way to manage it? I have already tried changing Null Processing to UnkownMember but still I am unable to see.
In my practice I always fill in dictionary tables with None value and map to this member all blank values.
But if you don't have any transactions with type TrxType2 how you can count them?
If you have next fact table:
Type_Id Owner_id ...
__________________________________________
1 13 (just for example)
1 8
0 11
0 4
Dictionary TrxType:
___________________________
id Code
0 None
1 TrxType1
2 TrxType2
your dimension can have the following hierarchy
Count of rows
All 4
-None 2
-TrxType1 2
-TrxType2 0
If you have different situation - please write an example.