With MDX is there a generic way to calculate the ratio of cells with regards to the selected members of a specific hierarchy? - ssas

I want to define a cube measure in a SSAS Analysis Services Cube (multidimensional model) that calculates ratios for the selection a user makes for a predefined hierarchy. The following example illustrates the desired behavior:
|-City----|---|
| Hamburg | 2 |
| Berlin | 1 |
| Munich | 3 |
This is my base table. What I want to achieve is a cube measure that calculates ratios based on a users' selection. E.g. when the user queries Hamburg (2) and Berlin (1) the measure should return the values 67% (for Hamburg) and 33% (for Berlin). However if Munich (3) is added to the same query, the return values would be 33% (Hamburg), 17% (Berlin) and 50% (Munich). The sum of the values should always equal to 100% no matter how many hierarchy members have been included into the MDX query.
So far I came up with different measures, but they all seem to suffer from the same problem that is it seems impossible to access the context of the whole MDX query from within a cell.
My first approach to this was the following measure:
[Measures].[Ratio] AS SUM([City].MEMBERS,[Measures].[Amount])/[Measures].[Amount]
This however sums up the amount of all cities regardless of the users selection and though always returns the ratio of a city with regards to the whole city hierarchy.
I also tried to restrict the members to the query context by adding the EXISTING keyword.
[Measures].[Ratio] AS SUM(EXISTING [City].MEMBERS,[Measures].[Amount])/[Measures].[Amount]
But this seems to restrict the context to the cell which means that I get 100% as a result for each cell (because EXISTING [City].MEMBERS is now restricted to a cell it only returns the city of the current cell).
I also googled to find out whether it is possible to add a column or row with totals but that also seems not possible within MDX.
The closest I got was with the following measure:
[Measures].[Ratio] AS SUM(Axis(1),[Measures].[Amount])/[Measures].[Amount]
Along with this MDX query
SELECT {[Measures].[Ratio]} ON 0, {[City].[Hamburg],[City].[Berlin]} ON 1 FROM [Cube]
it would yield the correct result. However, this requires the user to put the correct hierarchy for this specific measure onto a specific axis - very error prone, very unintuitive, I don't want to go this way.
Are there any other ideas or approaches that could help me to define this measure?

I would first define a set with the selected cities
[GeoSet] AS {[City].[Hamburg],[City].[Berlin]}
Then the Ratio
[Measures].[Ratio] AS [Measures].[Amount]/SUM([GeoSet],[Measures],[Amount])
To get the ratio of that city to the set of cities. Lastly
SELECT [Measures].[Ratio] ON COLUMNS,
[GeoSet] ON ROWS
FROM [Cube]
Whenever you select a list of cities, change the [GeoSet] to the list of cities, or other levels in the hierarchy, as long as you don't select 2 overlapping values ([City].[Hamburg] and [Region].[DE6], for example).

Related

Pivoting DB2 data on multiple conditions

I'm trying to get a query together that selects products based on a combination of data (body type, materials and colors,etc.) and I've gotten close but I'm still missing a step to get exactly what I want. I've been looking more at pivoting data and I've tinkered with this query but I'm still left with this issue.
Basically, I have multiple products that only have one material and color attributed to them and they each have a unique stock keeping ID, but some of the body types will have 2 materials and colors per stock keeping unit.
My current results in this db fiddle https://www.db-fiddle.com/f/u4zKAdw3H4hFLbfnzEeZS2/1
are as shown:
For the most part the results are there but BodB has the same color for both materials and should be one single row like BoDB | Fabric | Black | Leather | Black
So if one body code is attached to 2 different materials but the same color with sequence 1 and 2, it should be a single row effectively grouped by the body and the color (the materials wouldn't be the same, only the color. And there will only ever be up to 2 materials and colors on a given stock keeping unit
The fiddle is ready to go with these results, any help is much appreciated

Cognos calculate using a different layout section

I have a Cognos report that has four different sections/layouts, each containing their own list. I would like to use one section to perform calculations using another list from another section. Is that possible?
For example:
Section Two contains a list with Name, Week1 Commissions, Week2 Commissions, etc
I want Section One to calculate the first 11 weeks only so the List in Section One would contain
Name, Weeks 1 through 11 total.
What is the best way to make this happen if it's possible.
Section One would contain these columns which would perform the calculations
Name Week 1-11 totals |
Section Two would have these columns
Name Week 1 Week 2 Week 3 .....
Best,
Kev
Yes it is possible, and you can perform all of the logic in one query
There are many ways to do this
For example, the four different sections/layouts, selecting the list, go to properties you can use the same query for each list

SSRS Lookup on single dataset

Hopefully you can help!
I have a single data source in my SSRS report. With this data source, I have populated a tablix. The tablix looks something like this:
SalesPerson ID Group Sales
Sarah 1 1 1234
Ross 2 1 555
Gemma 3 2 678
Jill 4 2 345
Jack 5 3 987
Peter 6 2 432
Henry 7 2 356
The report is set up to create a different page for each of the sales people. for example, on the first page of the report, only first record would be shown (the record that holds Sarah's information, the second page would show the record for Ross' information ,etc..)
The issues I face is this:
At the bottom of the report, I need to include a textbox that displays the group number that the specific employee belongs to (the employee who is currently being displayed on the page).
I think that I need to do some sort of lookup on the IDReportItem to return the group ID in order to do this, but have had no luck in my attempts.
I understand that this is a horrible way of doing things, but I am limited to using this single dataset for performing this task.
Any help you can provide will be greatly appreciated,
Thanks you!
Unfortunately there doesn't seem to be a way to do this in a single textbox, but you can do it with a second tablix that uses the same dataset.
Create your second tablix and position it at the bottom of the page, then set your grouping to be the same on both tablixes and use the second tablix to only display the group ID, plus whatever label you want.
Create a new row group for each tablix (grouping on group ID), then right click the group and browse to Group Properties -> Page Breaks and check the box that says "Between each instance of a group". Do this for both tablixes.
This is what grouping is designed for. Build your table, and set the page break attribute to true.
You can have multiple rows under your group. Since your group is a field, simply add it to the detail row.
Your grouping is obviously set up right to get the report paging correctly.
You could add a List to the report, set the grouping on that (with page break between groups)
Inside the list - Add a RECTANGLE. (this be important!)
Once you've added the rectangle, you can add another as many objects as you like. In your case I think that may be a matrix and a text box
eg
Then it just becomes as spacing issue (to get the page looking right)

Conditional Drill Down Powerview

Not sure if this is doable but I just wonder say if my data set got this structure
Department, Team, Service, Area
and I got a measure lets call it #count that count all rows in this table.
When create a powerview chart I want to be able to drill down by Department, Team, Service and Area.
However if say in Area there are following attributes
Area 1 - 10 rows
Area 2 - 5 rows
Area 3 - 3 rows
Is it possible to stop drill down if count row in certain area is less than 5 per se?
Appreciate all advice.
Many thanks
Peddie

Grouping dimension members using mdx query on the fly with aggregation

I am new to MDX and I just want to ask if it is possible in MDX query to make aggregations and groupings on the fly.
Here is the scenario, I have a dimension called "Department". And it has department code values e.g.
1234
1257
1346
1390
I also had a measure called "Sales".
What I need to do here is to make a Calculated Member that will get the Maximum "Sales" grouped per department based on the its first two digits. For example, consider the following output when browsing the cube using the Department dimension and Sales Measure
Department | Sales
1234 | 100
1257 | 200
1346 | 100
1390 | 400
Then I need to make an MDX query to produce an output something like below,
Department | Sales
12xx | 200
13xx | 400
You will notice that Maximum Sales based on the two digits of each department concatenated with "xx" string were the expected output.
Well determining the maximum is not a problem. with <name> as max(<something>) but you should reconsider the approach with the on the fly grouping.
I'm sure, that it is achievable, although I cannot provide a solution, but it will perform poorly. (I'm assuming that the digits of the department are not implemented as measure)
If you need this grouping more often you should add an additional dimension, or better a hierarchy to the department dimension.