I need to create cube calculation for median Age in a HR cube.
Measures: head count and FTE
Dimension: Age (Age, Age_Group, ...), Duty_type, Staff (Staff_ID, ...), Date, etc
I tried to use the following MDX script:
Median([Month Date].[Staff Profile Month Date - Hierarchy].[Month Date Calendar Year].currentmember.Children ,IIF([Age].[Age].currentmember.name ='All' ,0,StrToValue([Age].[Age].currentmember.name)))
I used the following help: http://msdn.microsoft.com/en-us/library/ms145570.aspx
How can this be solved?
Create base measure called Sum Age(make it invisible) and use this to create median calculated measure.
Median([Staff].[Staff ID].currentmember.children,[Measures].[Sum Age])
Related
I created a query in Microsoft Access such as the one below:
SELECT LoanType
,Avg(Loan Amount)
,Avg(Loan Rate)
FROM Table1
GROUP BY LoanType
The output is as you would expect, the average loan amount and the average loan rate for each loan type.
However, I'd like for my Access Report to calculate the average of all the loans, regardless of loan type, and place this row at the very bottom. Using the Report view in Access, you can add a "Totals" row where you can write a formula such as COUNT(), SUM(), AVG(). But as you know, calculating an average of an average goes against basic math.
I'm assuming I have to create this "Totals" row at the SQL/Query level. But I can't seem to figure it out. Any input would be greatly appreciated!
You can use UNION ALL to add a row with a similar query, just without the GROUP BY and a NULL for LoanType (or any other value you like as long as it's implicitly castable to the data type of LoanType).
SELECT LoanType,
Avg(Loan Amount)
Avg(Loan Rate)
FROM Table1
GROUP BY LoanType
UNION ALL
SELECT NULL,
Avg(Loan Amount)
Avg(Loan Rate)
FROM Table1;
Of yourse you can do exactly what you described: Build a query that calculates the averages by LoanType, build a report on this query and calculate an average in the report footer. Unfortunately, this "total average" will be an average of averages, but I guess you want an average over all records. To achieve this:
Base your report on Table1.
Create a group to group by LoanType.
Calculate the averages by LoanType in the group footer.
If you don't want to see the details, set the details section to be invisible.
Calculate the "total averages" in the report footer.
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).
I have successfully added basic sum/count/etc.. simple measures, but have no idea how to add more complex one.
Let's assume that data structure represent tracks with goods and have next structure:
date
id_track
id_articte
amount
cost
And want to calculate next measures:
average item price, calculated as sum(cost) / sum(amount)
average track cost. It's average between sum(cost) for whole tracks. Sql expression looks like sum(cost) / count(distinct id_track)
What is the right way to add this measures to my cube, in case i will need them in Excel over XMLA?
Complex calculation are solved using what we call in MDX 'calculated measures'.
Calculated Measures support the whole power of MDX language. You can see more information about Calculated Measures here. They are very powerful and over 100 functions are supported (function list).
If you want to define a calculated measure once per schema I'd advise defining them in Advanced/Scripts in the Builder UI tab. You can first check validity in the MDX IDE and once validated move them to the Script.
average item price, calculated as sum(cost) / sum(amount)
This would look something like the following:
WITH MEMBER [Measures].[AvgPrice] AS
AVG(
EXISTING([Item].[Item].MEMBERS)
,[Measures].[COST]
)
...
Or
WITH MEMBER [Measures].[AvgPrice] AS
[Measures].[COST]
/
[Measures].[AMOUNT]
...
average track cost. It's average between sum(cost) for whole tracks.
Sql expression looks like sum(cost) / count(distinct id_track)
WITH MEMBER [Measures].[AvgTrackCost] AS
AVG(
EXISTING([TrackItem].[TrackItem].MEMBERS)
,[Measures].[COST]
)
...
I've had to guess that the following exist within your cube:
[Measures].[COST]
[Measures].[AMOUNT]
[Item].[Item].MEMBERS
[TrackItem].[TrackItem].MEMBERS
I am new to BI and need help to create a calculated member.
I have a cube with following dimension and measure:
Dimension tables:
Dim_Time (Year, Month, Day)
Dim_MyValueCollection: DataType with data types having values 'Gross Paid Claims' and 'Gross Written Premiums'
Measure:
FactTable.Value
I need to create a calculated member on Dim_MyValueCollection.DataType to represent the difference of 'Gross Written Premiums' values in current and previous year.
To get data from a previous period in mdx you can use these functions:
Lag
https://msdn.microsoft.com/en-us/library/ms144866.aspx
ParallelPeriod
https://msdn.microsoft.com/en-us/library/ms145500.aspx
Have you attempted any mdx ?
Edit
Here is a general tuple for the change in Gross Written Premiums since the same period in the previous year. I've guessed the names of your dimensions because you have not supplied any sample mdx:
([Time].CURRENTMEMBER, [Measures].[Gross Written Premiums])
-
(PARALLELPERIOD(Year,1,[Time].CURRENTMEMBER), [Measures].[Gross Written Premiums])
This is a slight modification of what I stumbled upon while searching the web:
Let's say I have a dimension PROJECTS which contains:
project_id - unique id
category - category of a cost
project_date - date of summing up the cost
My warehouse also has the dimension of TIME with date, and a dimension COSTS containing values of costs. Those three dimensions are connected by the measure group EXPENSES which has:
id_date
id_cost
id_project
I want to wirte an MDX query which would group the projects by their category, and sum up all the costs, but only those which do not exceed the date given in the project_date attribute of the dimension PROJECTS (each category has the same project_date, I know it's redundant but I can't change it..)
I'm not sure, but maybe something alongside this?
SELECT
[COSTS].[COST] ON 0,
[PROJECTS].[category] ON 1
FROM [CUBE]
WHERE
[PROJECTS].[project_date] < #project_date