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

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.

Related

Many to many relationship with hierarchy in SSAS

I am new to SSAS and have a situation where I need help.
I have a many to many relationship table which contains info about the competitors of a property and the type of competitor it is at any given date.
So, something like this:
PID Type CompID Date
1 A 1 1/1/2001
1 A 2 1/1/2001
1 B 1 2/1/2001
1 B 1 3/1/2001
2 A 1 1/1/2001
2 B 1 1/1/2001
Now I need to include this in the cube and relate it to the main fact table. I have defined the relationship as a many to many but while writing the query to retrieve the information using MDX, I am stuck.
What I need is all the measures for a given property and all the aggregated measures of all its competitors of a given type at a given date.
So, given a proeprty ID, I need to identify the list of its competitors of a given type and on a given date and then I have to aggregate the measures for all these competitor properties.
I am stuck at this place where I have to identify all the competitors of a given property.
e.g. if I fire this query:
Select
{
TYNBC,YOYNBC_Improvement,LYNBC,TYADR,YOYADR_Improvement,LYADR
}
on 1,
Stay_DATE.Month.Month on 0
FROM Cube1
where {Hotel.Hotel_Key.&[480]}*{Stay_DATE.Hierarchy.Year.&[2015]}
The result would be the measures for a given property.
What I want in the result is all the above measures and the same measures for the competitors of the property 480 for a given date and a given competitor type. The issue I am facing is in identifying the competitors of the property in mdx because competitor table is added as a factless fact with many to many relationship in the cube. So, how do I retrieve the list of competitor properties when there is no hierarchy defined as it is not a dimension.
Thanks for your help in advance.

Storing one to many relation in database - Array or one to many relation?

When we store a one to many association in a database, which is a better approach. One - Many mapping in a table or storing the many part as an array. I'm specific to postgres database (constraint)
For example: If we define the relationship as follows
a b
1 - 2
1 - 3
1 - 6
2 - 3
2 - 4
3 - 5
3 - 6
Here, the one part is a and the many part is b (Primary key being a, b)
The same thing can be stored as an array as (similar to an adjacency list).
1 - {2,3,6}
2 - {3,4}
3 - {5,6}
Which of this is more efficient. I may have to do some operations on this such as transitive closure etc. and, the graph may be really huge.
A practical example of the above may be something like connections of a particular profile (LinkedIn connections), or any social graph scenario
In your example the relationship is many to many, not one to many. Multiple a records can be associated with one b and multiple b records can be associated with one a. As such, the correct normalized form is a join table.
Hypothetically, imagine this DB relationship represents one profile "liking" another profile in a social media context. In that case you may want to store additional information; a timestamp of when the "like" was initiated, the degree to which the profiled shruged/liked/loved the other profile, etc. It then becomes apparent that in the array implementation there is nowhere to store this additional data. You need a join table so that each "like" can have its own metadata.
Here is the structure I would recommend:
PK A B
100 1 - 2
200 1 - 3
300 1 - 6
400 2 - 3
500 2 - 4
600 3 - 5
700 3 - 6
Where PK is an auto generated PK, hopefully from a sequence, and A, B are constrained by a unique index. This structure is future proof for eventually dropping the unique index on A, B, a headache I've had to deal with occasionally.

Grouping attributes in 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...

Complicated SQL query vs datatable iteration and proccessing

I have a three table structure in SQL Server 2012: people, connections and messages. The affected schema would be like this:
People: Id (pk bigint), name...
Connections: Id (pk bigint), IdPpl1 fk, IdPpl2 fk
Messages: Id (pk uniqueidentifier), Idconnection (fk), Messagetype (smallint)
On the Connections table, IdPpl1 and IdPpl2 are fk's to people Id. It could happen to appear in this table the same "two people" but swapping their column, E.G:
Id IdPpl1 IdPpl2
.. ...... ......
3 101 105
8 105 101
9 101 106
10 106 101
The above situation is correct. Actually, those are the maximum occurrences of these "two people" in the table.
The Messages table holds the information of which "connection" sent a message.
Id IdConnection Messagetype
.. ............ ...........
24 3 1
25 8 1
26 3 2
27 8 2
28 9 3
29 10 2
(Note: the messages are one-way, that's why there can be two rows in the connections table affecting the same two people: on the first row, one person is the sender and the other the receiver, on the second row they swap)
Given a People Id, I need a SQL query to show "least connectiontype messages mutually sent by mutually connected people" and an extra colum indicating if the messagetype matches or not. The result should be like this, for People Id 101:
Person_id Person_name IdConnection MatchingMsgType
......... ........... ............ ...............
105 John 3 1
106 Peter 9 0
The first row appears because of MsgIds 24 and 25. A potential row corresponding with messages 26 and 27 won't appear because a previous matching messagetype was found.
The second row appears because of MsgIds 28 and 29, marking the messagetype as non-matching.
Currently I get all the "messages related to a person" and iterate through the datatable sorting, filtering and operating in-memory.
Would you go with a full-SQL solution (I want to preserve full isolation between app tiers) or is more suitable the datatable iteration?
Thanks in advance!!
Obviously it depends on the length of the resulting set of your current db query (the one resulting in all rows related to a user). It is not clear if rows are ever removed from you tables. If not, your solution does not scale, since the number of matching rows will grow for ever. If instead you can assert the the number of resulting rows has some bound (for example: the maximum number of connections a user can open at the same time) then your solution might be good enough.

SQL (Access): Multiple values per "ID" - Store as TRUE unless any FALSE

Good afternoon!
I have recently come across an issue that I am hoping can be solved with your help. Our system is [sadly] ran on Access (2007). I have decent experience with SQL and elect to use this method for most of queries rather than the Design View. However, this is the issue I have come across recently:
A table (with its own primary key of course) contains the ParticipantID and Records. This table may contain multiple records per person due to having events at various locations. With this information we track whether or not each record is within our system already due to the location falling under our large "umbrella" (Internal). To make it look simple, it looks something like this, ignoring the primary key as we only care about the participant ID.
ParticipantID Internal
1 -1
1 -1
2 0
3 -1
3 -1
3 0
4 -1
4 0
I want to be able to say if ANY of the records of a participant are not Internal (eg. =0), then in this query's results, store it as 0.
Hence, the results table would look something like:
ParticipantID Internal
1 -1
2 0
3 0
4 0
Does this make sense? Thank you in advance!
You can use Max:
SELECT internal.ParticipantID, Max(internal.Internal) AS MaxOfInternal
FROM internal
GROUP BY internal.ParticipantID;
I built the above using the query design window.
If the values Internal can be only 0 and -1 the following may help
Select ParticipantID,max(internal) from thetable
Group by ParticipantID