Designing Fact table associated with multiple attribute hierarchy members - sql-server-2008-r2

I am designing a warehouse to accommodate a movie related database. I have a table with the columns - Title, Genre, SalesAmount, ProductionAmount.
One such row would be say GodFather, Crime|Drama,1000000,20000.
I want to move this to DW, I am looking at getting this into a Fact table say FactSale and have linkage to Genre dimension.
My objective is to analyze revenues by Genres. In this case, how would I be building the cube matrix? I have another mapping table with TitleId,GenreId present.
Also would it be possible to create a dynamic hierarchy say under Action, Drama, Romance etc. Idea is to gather info on a single genre or combination of genres.
Can someone guide me on how to go about it?

I have found the answer. Thanks to the whitepaper from SQLBI with extensive examples and explanations - http://www.sqlbi.com/wp-content/uploads/The_Many-to-Many_Revolution_2.0.pdf

Related

Tableau: relationship between tables with different fields

I am really new to Tableau.
I have an "accident" table (excel) that describes each traffic accident in the past few years, including its "district" (location). I have another "district" table that describes each district of the city, including its population.
Now I want to join those two tables and create a graph of accidents per person for each district.
The problem I face is: The two excel files are from different databases, which means that the same district may appear to have different names in two tables. How do I let tableau know the matching between districts?
Could you tell me how I can join those two tables so that I can create my chart?
Please let me know if there are any problems with my approach or understanding. Thank you in advance!
Assuming I understand question correctly.
Your accident transactions might have..
District#1, Accident Date, ,
District#2, Accident Date, ....
District#3, Accident Date, ....
Your district dimension table has 1 unique record per district, but names don't match.
District1, CityName
District2, CityName
District#3, CityName
You want to combine the results correctly...
Excel is the preferred datasource?
I assume the actual sources of data do NOT have a singular "code" value for the district name that actually does match. This is where MDM is important for system integrations. Right answer IMO is to actually have source systems/dbms understand that they are integrated and create XREF in 1 system that is required when a district is setup or exists.
Options. I think you need to "clean" the data someplace. The question is where.
MDM in your source system integrations.
Are the excel sources created in automated fashion? You could create a manual XREF excel sheet and lookup/decode one of the district values to conform a single definition of the district. In addition to your graph. create an audit that looks for any new data that doesn't "lookup" correctly to know to maintain the manual XREF.
Probably could create calculated XREF is tableau calc itself and then blend based on that calculated field. I think that would require full desktop versus web editor.
Tableau Prep might help as well. (although my company doesn't use this)

Relational data with modifications/variants

Let's say a supermarket has one table with statistical revenue data by business day. In a second table they want to try out different variations of these data, f.e. less bakery revenue at 1st January, one more public holiday or maybe opening on sundays.
I do not want to duplicate the whole revenue data of a year or more for just a few variations. Additionally it should be easily possible to show the diff between the base table and one alternative scenario.
To make it a little more clear, I created a demo case at SQLFiddle. SUPERMARKET_DAYS is the table with the base revenue data. ALTERNATIVES are the variations/alternatives or scenarios (however you want to name it) and ALTERNATIVE_DAYS is a table with a similar structure as the first one and holds the concrete changes.
Example at SQLFiddle
SUPERMARKET_DAYS
(
ID,
DAY,
NUM_CUSTOMERS,
NUM_VISITORS,
REVENUE_BAKERY,
REVENUE_BEVERAGE,
REVENUE_CANNED,
REVENUE_DAIRY,
REVENUE_DRY,
REVENUE_FROZEN,
REVENUE_MEAT,
REVENUE_CLEAN,
REVENUE_PERSONAL_CARE,
REVENUE_PAPER,
REVENUE_OTHER
)
ALTERNATIVES
(
ID,
TITLE
)
ALTERNATIVE_DAYS
(
ID,
DAY,
NUM_CUSTOMERS,
NUM_VISITORS,
REVENUE_BAKERY,
REVENUE_BEVERAGE,
REVENUE_CANNED,
REVENUE_DAIRY,
REVENUE_DRY,
REVENUE_FROZEN,
REVENUE_MEAT,
REVENUE_CLEAN,
REVENUE_PERSONAL_CARE,
REVENUE_PAPER,
REVENUE_OTHER
)
I do not even know, if this schema design makes any sense but it illustrates the problem.
How would you store this kind of data?
I thought about something like a versioning table but this does not really solve my problem.
I could merge both tables inside of my java code.
Is there something like the MERGE functionality for views?
I would really be grateful for every kind of idea or the correct keyword for my own investigations. This problem should already exist but I didn't find much to solve it, so I maybe did not search with the correct terms.
Thank you everybody!

list of all valid parameters and criteria that can be used in RMA queries

I would like to get specific neuron models and even though I believe I understand the RMA query system, I can not find a list of the valid keywords/arguments/criteria/parameters that would correspond to what I am looking for.
For example 'homo sapiens' as donor species is valid, and makes sense.
But if 'm__biophys_perisomatic' returns all cells with perisomatic biophysical models, what about 'all active' ones (just an example, I would be interested in many other categories)?
I assume it is obvious but I will not stumble upon it until I have posted this question.
Thanks for your question. You can see what fields and associations are available for a table using the describe route. For example:
http://api.brain-map.org/api/v2/data/NeuronalModel/describe.xml
From your question, I believe you're looking at this table:
http://api.brain-map.org/api/v2/data/ApiCellTypesSpecimenDetail/describe.xml
You can use m__biophys_all_active to see if a cell in that table has an all-active model.
FYI: The ApiCellTypesSpecimenDetail table is a denormalized table, which means it combines a complex set of relationships among tables into a single flat table.
You could similarly use the following, more generic query to find the all-active models.
http://api.brain-map.org/api/v2/data/query.xml?criteria=model::NeuronalModel,rma::criteria,neuronal_model_template[name$eq'Biophysical - all active']&num_rows=150

MS Access link record from forms

There are two tables, one for Student and one for Borrowed Books. In the Microsoft Access (2010, 2013), it is easy to display a form Student based on the table Student, and other form BorrowedBooks based on the table Borrowed Books with their Record Source pointed.
How to do Form BorrowedBooks showing records for the current student showing on the Form Student one at one time? I'm looking to learn both VBA script and using the built-in controls to achieve the result.
Relationship between has been built. And it's one student to many books relationship.
One VBA approach like:
DoCmd.OpenForm "BorrowedBooks", , , "StudentID = " & Me.StudentID
The real trick is figuring out which event to put code into.
Another option is to use form/subform arrangement - main form bound to Students table and subform bound to BorrowedBooks. Have you looked at Microsoft Lending Library database template?
so if my understanding of your question is clear then you need to join operation on the tables
SELECT *
FROM
student
INNER JOIN borrowedbooks ON (The two table'S related column ie student.pk=borrowedbooks.fk)
you can also add a where clause if you want from here you can state you primary key in student table and it relationshi

Need a good database design for this situation

I am making an application for a restaurant.
For some food items, there are some add-ons available - e.g. Toppings for Pizza.
My current design for Order Table-
FoodId || AddOnId
If a customer opts for multiple addons for a single food item (say Topping and Cheese Dip for a Pizza), how am I gonna manage?
Solutions I thought of -
Ids separated by commas in AddOnId column (Bad idea i guess)
Saving Combinations of all addon as a different addon in Addon Master Table.
Making another Trans table for only Addon for ordered food item.
Please suggest.
PS - I searched a lot for a similar question but cudnt find one.
Your relationship works like this:
(1 Order) has (1 or more Food Items) which have (0 or more toppings).
The most detailed structure for this will be 3 tables (in addition to Food Item and Topping):
Order
Order to Food Item
Order to Food Item to Topping
Now, for some additional details. Let's start flushing out the tables with some fields...
Order
OrderId
Cashier
Server
OrderTime
Order to Food Item
OrderToFoodItemId
OrderId
FoodItemId
Size
BaseCost
Order to Food Item to Topping
OrderToFoodItemId
ToppingId
LeftRightOrWhole
Notice how much information you can now store about an order that is not dependent on anything except that particular order?
While it may appear to be more work to maintain more tables, the truth is that it structures your data, allowing you many added advantages... not the least of which is being able to more easily compose sophisticated reports.
You want to model two many-to-many realtionships by the sound of it.
i.e. Many products (food items) can belong to many orders, and many addons can belong to many products:
Orders
Id
Products
Id
OrderLines
Id
OrderId
ProductId
Addons
Id
ProductAddons
Id
ProductId
AddonId
Option 1 is certainly a bad idea as it breaks even first normal form.
why dont you go for many-to-many relationship.
situation: one food can have many toppings, and one toppings can be in many food.
you have a food table and a toppings table and another FoodToppings bridge table.
this is just a brief idea. expand the database with your requirement
You're right, first one is a bad idea, because it is not compliant with normal form of tables and it would be hard to maintain it (e.g. if you remove some addon you would need to parse strings to remove ids from each row - really slow).
Having table you have already there is nothing wrong, but the primary key of that table will be (foodId, addonId) and not foodId itself.
Alternatively you can add another "id" not to use compound primary key.