I have a table with columns that store dates of various events, like so:
<pre>
PersonID DatePassedExam1 DatePassedExam2
1 NULL NULL
2 01-11-2012 NULL
3 01-12-2012 10-12-2012
</pre>
I want to build a cube to see counts of people who have passed exam1 and exam2 by person attributes and time, e.g. year to date.
So,
YTD for Oct2012: exam1count=0, exam2count=0
YTD for Nov2012: exam1count=1, exam2count=0
YTD for Dec2012: exam1count=2, exam2count=1
I'm guessing this needs semi-additive aggregation?
I can't make changes in the database (without difficulty) and am not using Enterprise edition.
Any advice gratefully received.
Thanks,
Dal
I would unpivot your table to pass the columns: PersonID , Exam , DatePassed. Your sample data would result in 1 row for PersonID 2 and 2 rows for PersonID 3.
I would then create an Exam dimension and link it.
Then I would create the measure as a Distinct Count of PersonID.
Related
I have a data set structure similar to below.
Product Group
Item
Sunday_Capacity
Monday_Capacity
Tuesday_Capacity
etc.
Product GroupA
Item A
10
8
5
I would like to get a resulting data set that was Product Group | Item | Day of Week | Capacity.
I realize I could do this with a join for each day but would like to unpivot this information. I imagine I will have to dynamically split the day of week value with a spilt function.
I'm creating a cube whose stock values should only conclude the last day each month's balance and value.
Hence, I've created the following Query in SSMS:
Create table #theStockTable(
Stock int,
StockValue INT,
DateKey int
)
INSERT INTO #theStockTable
VALUES(3,5, 20170211),
(3,5,20170228),
(1,4,20170331),
(1,4,20170330)
SELECT CAST(CONVERT(varchar, DateKey, 112) AS numeric(8, 0)) AS DateKey, SUM(Stock) AS [CL Stock], SUM(StockValue) AS [CL Stock Value]
FROM #theStockTable
WHERE CONVERT(date, CONVERT(varchar(10), DateKey)) = eomonth(CONVERT(date, CONVERT(varchar(10), DateKey)))
GROUP BY DateKey
In SSMS this returns the correct values:
DateKey CL Stock CL Stock Value
20170228 3 5
20170331 1 4
However, when I create an OLAP cube using SSAS, and use the Query above as the Named Query for my fact table #theStockTable and the same Query as my only partition of the same fact table and deploy and execute the cube, I have a situation where I get different values on each day of every month, but I only want to have the values for each month's last day.
I have used New Project.. -> Import from Server (multidimensional model or data mining model) in SSAS. It is important that the users must be able to browse the cube as they presently do.
The cube whose meta data I have copied contains every day's values on the stock table. May there be some metadata change I need to make in addition to the Query modification I have done in Edit named Query.. in Data Source View and replacing the old Query in the partition with my new Query?
Hopefully someone can shed some light into this.
EDIT
To clarify my request, some users of the cube has explained that it is rather slow to browse in for instance Excel, mainly because my Stock measure is much bigger than it is required to be. As it is now, it returns every StockValue and Stock of each product and each day. I want to only include the total balance of StockValue and Stock of the last day of the month. All other stock values are redundant.
For instance, browsing my DimDate dimension table with the measurements Stock and StockValue should have this return set:
DateKey Stock StockValue
20170131 0 0
rather than the whole return set which is returned now:
DateKey Stock StockValue
20170101 3 5
20170102 4 6
20170103 1 1
20170131 0 0
I think you already had a date dimension in your cube, if yes, then follow these steps:
Add an additional attribute [IsLastDay] with value 0/1 in the date dimension to indicate if the current date record is the last day of that month or not.
2.Add a calculate measure [CalStock] with this formular:
([Measures].[StockValue],[Date].[IsLastDay].&[1])
3.Fire this query to return the expected result:
select {[CalStock]} on 0,
non empty{[Date].[Date].[Date]} on 1
from [YourCube]
I have to design a cube for students attendance, we have four status (Present, Absent, Late, in vacation). the cube has to let me know the number of students who are not present in a gap of time (day, month, year, etc...) and the percent of that comparing the total number.
I built a fact table like this:
City ID | Class ID | Student ID | Attendance Date | Attendance State | Total Students number
--------------------------------------------------------------------------------------------
1 | 1 | 1 | 2016-01-01 | ABSENT | 20
But in my SSRS project I couldn't use this to get the correct numbers. I have to filter by date, city and attendance status.
For example, I must know that in date X there is 12 not present which correspond to 11% of total number.
Any suggestion of a good structure to achieve this.
I assume this is homework.
Your fact table is wrong.
Don't store aggregated data (Total Students) in the fact as it can make calculations difficult.
Don't store text values like 'Absent' in the fact table. Attributes belong in the dimension.
Reading homework for you:
Difference between a Fact and Dimension and how they work together
What is the grain of a Fact and how does that affect aggregations and calculations.
There is a wealth of information at the Kimball Groups pages. Start with the lower # tips as they get more advanced as you move on.
My goal is to build a fact table which would be used to derive measures in SSAS. The measure I am building is 'average length of employment'. The measure will be deployed in a dashboard and the users will have the ability to select a calendar period and drill-down into month, week and days.
This is what the transactional data looks like :
DeptID EmployeeID StartDate EndDate
--------------------------------------------
001 123 20100101 20120101
001 124 20100505 20130101
What fields should my Fact Table have? on what fields should I be doing the aggregation? How about averaging it? Any kind of help is appreciated.
Whenever you design a fact table, the first set questions to ask yourself is:
What is the business process you're analysing?
What are relevant facts?
What are the dimensions you'd like to analyse the facts by?
What does the lowest (least aggregated) level of detail in the fact table represent, i.e. what is the grain of the fact table?
The process seems to be Human Resources (HR).
You already know the fact, length of employment, which you can calculate easily: EndDate - StartDate. The obvious dimensions are Department, Employee, Date (two role-playing dimensions for Start and End).
In this case, since you're looking for 'average length of employment' as a measure, it seems that the grain should be individual Employees by Department (your transactional data may have the same EmployeeID listed under a different DeptID when an employee has transferred).
Your star schema will then look something like this:
Fact_HR
DeptKey EmployeeKey StartDateKey EndDateKey EmploymentLengthInDays
-------------------------------------------------------------------------
10001 000321 20100101 20120101 730
10001 000421 20100505 20130101 972
Dim_Department
DeptKey DeptID Name ... (other suitable columns)
------------------------- ...
10001 001 Sales ...
Dim_Employee
EmployeeKey EmployeeID FirstName LastName ... (other suitable columns)
---------------------------------------------- ...
000321 123 Alison Smith ...
000421 124 Anakin Skywalker ...
Dim_Date
DateKey DateValue Year Quarter Month Day ... (other suitable columns)
00000000 N/A 0 0 0 0 ...
20100101 2010-01-01 2010 1 1 1 ...
20100102 2010-01-02 2010 1 1 2 ...
... ... ... ... ... ...
(so on for every date you want to represent)
Every column that ends in Key is a surrogate key. The fact you're interested in is EmploymentLengthInDays, you can derive a measure Avg. Employment Length and you would aggregate using the average across all dimensions.
Now you can ask questions like:
Average employment length by department.
Average employment length for employees starting in 2011, or ending in September 2010.
Average employment length for a given employee (across each department he/she worked for).
BONUS: You can also add another measure to your cube that uses the same column, but instead has a SUM aggregator, this may be called Total Employment Length. Across a given employee this will tell you how long the employee worked for the company, but across a department, it will tell you the total man-days that were available to that department. Just an example of how a single fact can become multiple measures.
I'm actually working on Oracle reports. One of the situation I have is to create a parameter for the reports which is type of fees. I have a table called type_of_fees and one of the column is called type_of_fees
I have several records such as:
monthly rental 1
monthly rental 2
monthly rental 3
1 month deposit
2 months deposit
Aircond charges
Utility
1 month advance
-weekly rental
For the parameter, I would like to have a list of values to choose from which I intend from the dropdown:
Monthly Rental
Deposits
Airconditioning
Utilities
Others
So I would like when user select monthly rental it will show types of monthly rental I got in the table _onthly rental 1,monthly rental 2, monthly rental 3.
I would also like if other records such as the 1 month advance and weekly rental to be put under Others when selected. Now,if I'm not mistaken, I'm going to have to create a view to make things easier
I would imagine needing columns like SELECTION_TYPE and TYPE_OF_FEES.
how would i insert custom records such for the SELECTION TYPE which will show the appropriate type of fees?
example of view intended:
----------------------------------
selection_type | type_of_fees |
----------------------------------
Monthly Rental | monthly rental 1
----------------------------------
Monthly Rental | monthly rental 2
----------------------------------
Monthly Rental | monthly rental 3
----------------------------------
Deposits | 1 month deposit
----------------------------------
Deposits | 2 months deposit
----------------------------------
Airconditioning | Aircond charges
----------------------------------
Utilities | Utility
----------------------------------
Others | 1 month advance
----------------------------------
Others | weekly rental
----------------------------------
How do I create this? especially the part to create data for the selection_type column. I'm not very familiar in creating views.
I have no problem querying out the data I intend to use but I just need to create the view so that I can use the selection_type to query out things easier:
SELECT DISTINCT TYPE_OF_FEES FROM TYPE_OF_FEES
WHERE TYPE_OF_FEES LIKE '%deposit%'
By the way I'm on Oracle. Please if anyone could explain and help.
I am going to assume you are referring to Oracle Reportwriter / Reportbuilder the product bundled with Oracle Forms?
Oracle Reports you have to start with the basics.
Create the report to select all data regardless of selection_type.
This will allow you to concentrate on the structure of the query and the structuring of the report. It's quite crucial to get the structure of your report correct and use this as a basis for the report wizard to generate the report for you. You then customize the generated report accordingly.
Once you have the structure pinned down - create your parameter form and add your parameter(s) into query.
You are probably looking to create two LOV parameter fields with the first being selection_type and the second being type_of_fees. The latter being dependent on the value entered in the first.
Oracle Reports Parameter Form documentation
I'm going to answer my own question since i have found a way, to create a view with that particular selection_type for each type_of_fees i can use CASE WHEN.
using that i can construct the view as i want with new columns.