Avg Over time in Cube - ssas

In fact table, I have column named BusinessDays.
In Cube structure , I choose "Avg over time (Business Days) "in usage when I create new measure named Measure A
I also have time dimension in cube.
In Calculations, I created measure B : Avg = SUM (Business Days)/Count (Business Days).
When I write the following MDX
Using Measure A
select A on 0,
[date].[Year].[2015] on 1
From Cube
Using Measure B
select A on 0,
[date].[Year].[2015] on 1
From Cube
But results are different from each other, Supposedly, results should be same.
Actually , Measure B is correct.
Any Idea ?

Related

Create MDX to Divide two measures for each month and then sum the all of the months

I have a multidimensional cube that needs a custom measure that I'm not sure how to build.
That data looks like this:
MemberID-----Date-------EventType
1--------------1/1/2016-------1
2--------------1/1/2016-------2
3--------------2/1/2016-------1
2--------------2/1/2016-------2
4--------------2/1/2016-------2
There is a count measure in the cube, but others can be added if needed. I need to create a measure that will use whatever filters the user applies and then count the EventType (1 and 2 only) by month, divide the resulting counts for EventType 1 into the count for EventType 2 (for each month individually), and finally sum the monthly results. For example 1/1/2016 would be 1/1=1 (count of EventType 1 and count of EventType 2) and 2/1/2016 would be 1/2=0.5 so the resulting measure value for the two months would be 1+0.5=1.5. Any help is greatly appreciated.
Let's assume you have a Date dimension with an attribute called Month. And let's assume you have an EventType dimension. And let's assume you have a count measure in your measure group called Cnt. Here's what else you need to do.
First, go to the DSV and add a new calculated column to the fact table which is called NullInt and is the following expression:
cast(null as int)
Then create a new Sum measure in your measure group off that column and call the measure My Rollup. Under the Source property, change NullHandling to Preserve so that it will start off null.
To explain why we're doing this, a scoped assignment to a physical measure will aggregate up. (If you assign a value to a physical measure at the grain of each month, then it will rollup to the grand total.) But a scoped assignment to a calculated measure doesn't roll up.
Then in your MDX script add the following calculations:
scope([Date].[Month].[Month].Members); //calculate at the month level then rollup
[Measures].[My Rollup] = DIVIDE(
([Event Type].[Event Type].&[1],[Measures].[Cnt]),
([Event Type].[Event Type].&[2],[Measures].[Cnt])
);
end scope;
Note that your version of SSAS probably has the DIVIDE function if it's AS2012 with the latest service pack or newer. But if it doesn't, you can always do division the old fashioned way as IIF(denom=0,null,num/denom).

How to do bitwise operations in SSAS cube for aggregations using MDX

I want to model a fact table for our users to help us calculate DAU (Daily active Users), WAU (Weekly active users) and MAU (Monthly active users).
The definitions of these measures are as follows:
1. DAU are users who is active every day during last 28 days.
2. WAU are users who are active at least on one day in each 7 days period during last 28 days
3. MAU are users who are active at least 20 days during last 28 days
I have built a SSAS cube with my fact table and user dimension table as follows
Fact : { date, user_id, activity_name}
Dimension: { date, user_id, gender, age, country }
Now I want to build a cube over this data so that we can see all the measures in any given day for last 28 days.
I thought of initially storing 28 days of data for all users in the SQL server and then do count distinct on date to see which measures they fall into.. but this proved very expensive since the data per day is huge..almost 10 millions rows.
So my next thought was to model the fact table (before moving it to SQL) such that it has a new column called "active_status" which is a 32 bit binary type column.
Basically, I'll store a binary number (or decimal equivalent) like 11000001101111011111111111111 which has a bit set on the days the user is active and off on the days user is not active.
This way I can compress 28 days worth of data in a single day before loading into data mart
Now the problem is , I think MDX doesn't support bitwise operations on columns in the expressions for calculated members like regular SQL does. I was hoping to create calculated measures daily_active_users, weekly_active_users and monthly_active_users using MDX that looks at this active_status bit for the user and does bitwise operation to determine the status.
Any suggestions on how to solve this problem? if MDX doesn't allow bitwise, what else can I do SSAS to achieve this.
thanks for the help
Additonal notes:
#Frank
Interesting thought about using a view to do the conversion from bitset to a dimension category..but I'm afraid it won't work. Because I have few dimensions connected to this fact table that have many-many relationships..for ex: I have a dimension called DimLanguage and another dimension called DimCountry and they have many-many relationship. And what ultimately I would like to do in the cube is to calculate the DAU/WAU/MAU which are COUNT(DISTINCT UserId) based on the combination of dimensions. So for ex; If a user is not MAU for dimension country US because he is only active 15 days out of 28 ....but he will be considered
You do not want to show the bitmap data to the users of the cube, but just the categories DAU, WAU, MAU, you should do the conversion from bitmap to category on data loading time. Just create a dimension table containing e. g. the following data:
id category
-- --------
1 DAU
2 WAU
3 MAU
Then define a view on your fact table that evaluates the bitmap data, and for each user and each date just calculates the id value of the category the user is in. This is then conceptually a foreign key to the dimension table. Use this view instead of the fact table in your cube.
All the bitmap evaluations are thus done on the relational side, where you have the bit operators available.
EDIT
As your requirement is that you need to aggregate the bitmap data in Analysis Services using bitwise OR as the aggregation method, I see no simple way to do that.
What you could do, however, would be to have 28 single columns, say Day1 to Day28, which would be either 0 or 1. These could be of type byte to save some space. You would use Maximum as aggregation method, which is equivalent to binary OR on a single bit.
Then, it would not be really complex to calculate the final measure, as we know the values are either zero or one, and thus we can just sum across the days:
CASE
WHEN Measures.[Day1] + ... + Measures.[Day28] = 28 THEN 'DAU'
WHEN Measures.[Day1] + ... + Measures.[Day7] >= 1 AND
Measures.[Day8] + ... + Measures.[Day14] >= 1 AND
Measures.[Day15] + ... + Measures.[Day21] >= 1 AND
Measures.[Day22] + ... + Measures.[Day28] >= 1 THEN 'WAU'
WHEN Measures.[Day1] + ... + Measures.[Day28] >= 20 THEN 'MAU'
ELSE 'Other'
END
The order of the clauses in the CASE is relevant, as the first condition matching is taken, and your definitions of WAU and MAU have some intersection.
If you have finally tested everything, you would make the measures Day1 to Day28 invisible in order not to confuse the users of the cube.

SSAS Time state rollup

I have the following situation (in SSAS):
http://i.imgur.com/D1xrYrv.jpg
Cube with two dimensions (Time / Alpha) and one measure (X)
Columns A - G is the result of the cube, with column G as the total sum.
How to get the average (like column H) instead of sum in SSAS?
It's called "Time state rollup" in Cognos, but how to get this in Microsoft?
I would try the Measure Aggregation Function: AverageOfChildren.

Create cube calculation in SSAS using MDX statement to allocate monthly target to daily level

I have a cube fact table for targets, the targets are at the monthly level (Jan = 300, Feb = 450, Mar = 350 etc.)
This is joined to the date dimension in my cube at using month as the join, however the dimensions grain is at the day level.
What I want to do is create a calculation so that the monthly target is allocated evenly to the days in the month so each day in Jan has a target of 300/31 Feb 450/28 etc.
I then want to be able to use this calculated measure as my target and have it available as the daily/monthly/quarterly/Annual Target.
I think this should be possible with an MDX statement (or perhaps a few using a few calculated measures) but I'm not that familiar with it.
So would this approach work and what would the mdx look like?
Thanks
If you have the ability to make changes to your source OLTP/staging database, then it would be best to change the grain of your Targets fact table to daily if you need to report at that level. You could do this with a view if you have a date dimension table in your OLTP database by joining your monthly fact table to your date dimension on the month attribute, and then evenly distributing the target value over the days of the month.
If you are using SQL Server and your OLTP schema looks like the following:
CREATE TABLE dimDate (
Date Date,
YearMonth Integer,
...
)
CREATE TABLE factMonthlyTarget (
YearMonth Integer,
Value Integer,
...
)
Your new fact view would be something like the following:
CREATE VIEW factDailyTarget AS
SELECT
dimDate.Date,
factMonthlyTarget.Value / Months.DaysPerMonth AS Value
FROM
factMonthlyTarget,
dimDate,
(
SELECT YearMonth, COUNT(*) AS DaysPerMonth
FROM dimDate
GROUP BY YearMonth
) Months
WHERE factMonthlyTarget.YearMonth = Months.YearMonth
AND Months.YearMonth = dimDate.YearMonth

calculating new measures in SSAS

I have a cube in my sql server analysis service (2012) project. One of my measures is withdrawn money from ATM. Now I want to have a new calculated measure that show me the growth of withdrawn money today toward to last day. It is a dynamic calculated measure.
Is there any solution for doing this work?
What you are looking for is most probably called a KPI = key performance indicator. Look here for information about how to add the metric you need.
if you want to show growth based on last value, for example today I Withdrew 10% less than yesterday, yo ucan use KIPs
if you want to show how much you Withdrew so far, you should use calculatins like YTD (year to date)
You should use KPI to build your measure.
Open your SSAS project in Visual Studio and double click on your cube.
In the KPI tab there is a panel with some samples of KPI using parallel periods.
This is an example to create an operating margin accross two periods :
IIf
(
KPIValue( "Gross Profit Margin" ) >
( KPIValue( "Gross Profit Margin" ),
ParallelPeriod
(
[<<Time Dimension Name>>].[<<Time Hierarchy Name>>].[<<Time Year Level Name>>],
1,
[<<Time Dimension Name>>].[<<Time Hierarchy Name>>].CurrentMember
)
), 1, -1
)