SSAS mdx to find monthly retention rate of employees - ssas

Here is my scenario. I have a cube designed to track the hiring process of an applicant for a job. So, they go from applying, to hired, and sometimes to termination.
I want to find the number of employees that are hired in a particular month and see how many of these same employees are still around in each month after.
So 10 employees were hired in July 2012, I want to get the number that have not been terminated in August 2012 and so forth.
July 2012 Hired August 2012 Sept 2012
10 9 remain 7 remain
My measures are [Hired Qty] and [Termination Qty].
I have role playing dimensions for date: [Hire Date] and [Termination Date].
I was thinking I need to get the Hired Month as a set and then subtract out the Termination Qty for each month after by the Termination Date dimension.

I think your design may not be optimal for solving this problem. In the past for student retention, I have used a transition matrix "pattern" as outlined here: The Many-to-Many Revolution 2.0
Let me know if you need more detail after looking through the solution.
To solve with your current model may require overly complex and non performant MDX calculations

You can create a measure with this expression:
Sum(NonEmpty('employees set', ([Measures].[Hired Qty], 'a hire date')),
([Measures].[Termination Qty], 'a termination date'))
The first argument of Sum will return the employees that were hired at your chosen date.

Related

dateadd in Redshift not compensating for leap year

I'm working on a YoY self join to see sales this year's and last year's sales numbers side by side in the same table.
The query looks something like this:
Select a.date_column, a.sales_column as ty_sales, b.sales_column as ly_sales
from sales_table a
left join sales_table b
on (dateadd(year, -1, a.date_column)) = b.date_column
This in theory should be fine, the problem is that 2016-02-29 records are joining to 2015-03-01 records, which is causing the numbers to be off for 02-2016.
Is this a known issue with redshift/postgres?
Let me know if I can provide any additional clarity.
I wouldn't say that it's a "known issue", it's how they decided to handle leap years. When you compare 2/29 for YoY, which day would you like to compare it with? If you compare it with 2/28 then are you also going to compare 2/28 of this year with 2/28 of last year? You're now comparing two days to the same day. Then you have to account for potentially double-counting those sales from last year when you total things up.
The short of it is that you need to come up with very specific business rules on how you want to handle leap years when it comes to reporting and then implement those rules, being careful to test them thoroughly given that date functions are often a bit arbitrary (for any database/language) when it comes to leap years.

Access Average Problems Between Names and Dates

I have a database that is more or less the following:
John Smith
Jan 1 2016
Sales $80
Jan 2 2016
Sales $100
Jane Doe
Jan 1 2016
Sales $85
Jan 2 2016
Sales $110
My report is setup to break on names and on dates (b/c in actuality there are more numbers than just sales, but I'm simplifying this question).
I need to find the average for a week, rolling 4 weeks, and month for each person. I can control the date range specified in the report using a form I made so I can get them to click a button that autofills a range of time based on today (a week would be the previous 7 days, etc).
I cannot however figure out how to make it average everything under a name. Using Avg, DAvg, and some "grouping" controls have not resulted in anything useable. DAvg got me the closest but it would average EVERYONE together instead of breaking each person by their name (which is "Employee Name" in the query).
Any help or ideas would be vastly appreciated! I don't care if it is a modification to the query language or the report itself as I'm versed in VBA, SQL, and Access to an extent. I came from doing things in Excel, so I'm no Access pro, but I'm great with Excel. Unfortunately that doesn't solve my problem here haha! Oh wait, that's not funny...doh!
Thanks everyone!
It should follow this line:
Select Person, Avg(Sales), Format(yyyymm, [Date])
From YourTable
Group By Person, Format(yyyymm, [Date])
For weeks it gets a little more complicated as weeks cross New Year.

ssas mdx query for previous previous month

am currently building a ssas cube. I need the default to bring back 2 periods in time. Last month and the month prior to that.
For last month I am using
tail(nonempty([service date].[quarter no - month no].members))
which works perfectly, however it is the previous month to this that I am struggling with.
Can anyone help please? Thankyou.
update:
I am using this mdx as a calculation inside SSAS to then use as a filter for the dataset inside ssrs.
My results are currently:
Contract Name Question TblFct Month Year
------------- ------- ------ ----- ---
New Homes How Many 600 Dec 2014
This is the number for the last month that has data in, i.e. December 2014. I am aiming to have another dataset that is automatically filtered by the same criteria but instead of the last non empty month, I am looking for the month preceeding that. I had looked at the lag function but haven't been able to make it stick for some reason.
My comparison dataset should yield:
Contract Name Question TblFct Month Year
------------- ------- ------ ----- ---
New Homes How Many 450 Nov 2014
The quickest solution is to use HEAD function before TAIL, but this is acceptable only in case of non-empty value in this period:
head(tail(nonempty([service date].[quarter no - month no].members),2),1)
But actually even your first solution for the last month may fail if you give users an opportunity to filter data by some dimensions in further SSRS reports with this kind of filters. As for my previous experience, it's better to set up month's parameter 'Last' as additional column/property and after that: as additional dimension hierarchy of current [service date] dimension.
In case of fully-dynamic behavior (when last month differs from report to report), please specify what is acceptable if prev. month is empty:
we need to show empty/zero value
we need to take previous non-empty member (this way it's implemented above)

Calculate Sum of Products Over Time With Changes in Historical Values

Given two (simplified) tables in Access 2010:
**tblDailyLabour**
DailyLabourID - PK
DateRecorded
EmployeeID
QtyHours
**tblEmployeeHistory**
EmpHistoryID - PK
DateApplicable
EmployeeID
PayRate
Employee1 is entered into the database today. He's set in an 'Address Book' of employees with various values assigned to him. As of today he has a PayRate of $23.50/hr.
So from today moving forward, all hours logged will be calculated against today's rate for Employee1 at (23.50 * [QtyHours])
A month goes by and Employee1 gets a wage increase to $25.00/hr. This value is logged as a new entry in the 'Employee History' and is active as of, say, April 17th. So from April 17th onward he is now being calculated at (25.00 * [QtyHours]).
On a daily report this is straight forward as a query checks the report date and calculates the totals for Employee1. Whether the report is March 17th or April 25th, the query looks up the assigned rate and figures the total cost.
However, if I were to create an administrative report that was to evaluate the total cost of all days between March 17th and June 3rd, there may be several changes in the employee rates that need to be accounted for.
This is where I'm having a problem. I can't figure out how to not show any previous rates if DateApplicable is <= DateRecorded.
How might I go about writing a query that determines the rate on each day - dependent on the value in the Employee History - and calculate a total sum?
I apologize in advance if this question isn't phrased very well, but thanks a heap for any help!
I think it might be easier if you did a date range (start date & end date) in the 'address book' instead of just the start date.
On the current record, make the end date 12/31/9999. When entering a new current record, update the end date of the last record.

Algorithm to convert fiscal periods to calendar periods

What I am trying to do
I am somewhat desperately trying to build an algorithm which converts financial figures from different companies from fiscal periods to calendar periods.
The problem
Fiscal periods often do not correspond to calendar periods, e.g. a company might report fiscal year 2011 revenues of 100 USD but its fiscal year does not end at the end of December 2011 but instead on September 2011. For instance, Apple's fiscal year ends end of September. Dell's fiscal year ends end of January and Intel's fiscal year ends end of December. For Apple and Dell, all fiscal quarter and fiscal half year ends are shifted as well.
In order to compare revenues or other financial metrics among these companies, I need to be able to convert each fiscal period into equivalent calendar periods. For instance, someone might ask, how much revenue each company generated in calendar year 2011.
In the case of Apple Corp., we would need to remove the revenues which have been generated in calendar period 2010, which would equal Apple's fourth quarter of FY2010 and add the first quarter of fiscal year 2012 (which ended December 2011).
What I have (data model)
My data model has the following attributes for each entity calendarPeriod and fiscalPeriod:
endYear (year in which the period ends)
endMonth (month number
1..12 at which last day the period ends)
length (number of months 1..12 of the period)
What I need (desperately)
What would be the most efficient and short algorithm I could accomplish this?
It would be great if the algorithm could handle "special situations" like Dell where it would need to take 1/3 of its fiscal first quarter, which ends awfully on January, of the following year and adding it to the last quarter of the preceding year. In addition the algorithm should be flexible enough to handle all period lengths and endMonths and try to combine periods if necessary (for instance for the first half of calendar year 2012, it should try to find a six month period which ends June 2012 or consecutively add two periods (one ending March 2012 and one ending June 2012 or taking a fiscal year which ends June 2012 and subtracting the quarters or half year which fall in calendar year 2011).
Thank you so much.
This is more of a financial question then technical question.
If you have end of year results only, there is no practical way you could compare unless they are for same financial period.
Further, if you somehow manage to get the monthly results and do some juggling to prepare comparable results, they will not be comparable as there are many accounting adjustments and provisions generally done in the end of year financial result and not in monthly results which you will miss here.
I would suggest that you should try to compare those results which yields more meaningful results.