Create custom count measure - ssas

I using an incident management cube to try to determine how many tickets were opened by a specific set of users. For instance, if there were 80,000 tickets opened - how many were opened by .[Submitter].&[xAutoData] and .[Submitter].&[xAutoVoice]?
Sounds pretty easy but I'm just learning MDX so this is a bit of an uphill battle. I'm thinking the best way is to use a custom measure but the closest I've got to any kind of result was by using this query.
WITH MEMBER [Measures].[AutoTickets] AS
COUNT({[INC - Incident Management].[Submitter].&[xAutoData],[INC - Incident Management].[Submitter].&[xAutoVoice]})
SELECT
{[Total Incidents],[AutoTickets]} ON 0,
{[INC - Incident Management].[Assigned Group]} ON 1
FROM [Incident Management Cube];
All it ever does is return '2' when there should be quite a bit more.
A point in the right direction would be appreciated and I think would help me learn what's going on behind the scenes.
Thanks!
EDIT:
Over the past few days, I've got a bit closer. I think I need to use a SUM function combined with an IIF.
Something like
WITH Member [Measures].[AutoTickets] AS
SUM(IIF([INC - Incident Management].[Submitter] = [INC - Incident Management].[Submitter].&[na\xData] OR
[INC - Incident Management].[Submitter] = [INC - Incident Management].[Submitter].&[na\xVoice],1,0))
But this returns an error. If I test the query without the SUM, the IIF part does work as expected so I think I'm missing one more piece on how I'm supposed to use the SUM function.

I think you need to clarify your question a little bit more in terms of what you want to achieve. From the query that you have provided, the calculated member "AutoTickets" counts only the set members of the [Submitter] attribute of [INC - Incident Management] dimension that you have provided with exact tuples and that number will always be 2 {xAutoData and xAutoVoice} across all dimensions, it's like a constant.
Suppose that you want to know how many [Submitter]'s contributed to the Total Incident measure, than I suggest that you try the following statement:
WITH MEMBER [Measures].[AutoTickets] AS
COUNT(NonEmpty({[INC - Incident Management].[Submitter].Members),([Measures].[Total
Incidents])})
SELECT
{[Total Incidents],[AutoTickets]} ON 0,
{[INC - Incident Management].[Assigned Group]} ON 1
FROM [Incident Management Cube];

Supposing that you have a measure "[Measures].[TicketCount]" which gives the count of tickets, the below query would give you tickets for
"[Submitter].&[xAutoData] and .[Submitter].&[xAutoVoice]". You just replace with the relevant measure.
select [Measures].[TicketCount] on columns,
{[INC - Incident Management].[Submitter].&[xAutoData],[INC - Incident Management].[Submitter].&[xAutoVoice]}
on rows
from [Incident Management Cube]

Related

How to count a total percentage for calculated measure in MDX (Mondrian)?

I have a problem which looked like a simple requirement ... it turned out it wasn't ... at least for me.
At the moment I feel like I've read half of the MDX internet ...
I'm using latest Saiku CE (Mondrian 4), and my simplified cube looks like this:
Dimensions:
Machine.Manufacturer
Measures:
Measure.[Msg count]
Measure.[Distinct machines]
Measure.[Distinct days]
Calculated measures:
Measure.[Msg xMxD] which is basically: (Measure.[Msg count] / Measure.[Distinct machines] / Measure.[Distinct days]).
Measure.[Msg xMxd %] which is: (Measure.[Msg xMxD] / SUM(Measure.[Msg xMxD], Machine.[Manufacturer].[All Manufacturers]))
What I want to accomplish is this table:
But as you've probably guessed, I have a problem with the Measure.[Msg xMxd %] measure ...
Because it is calculated on base of another calculated measure, the % calculation is done after the summing for a particular Manufacturer and I don't know how to overcome this.
The closest answer I found was this one: https://forums.pentaho.com/threads/160265-Calculate-members-in-mdx/
... but this concerns only one generated member as a sum of all manufacturers.
I've found also some resolutions based on Axis(...) functions but those are unavailable in Mondrian.
Do you have any ideas ? Is there a possibility to generate a set of calculated members ? this would (at least theoretically) give me a possible to set solve order for all child members of [Machine].[Manufacturer]
Any help is much appreciated.

SSAS: Get a distinct Count based on two different elements

I need to create a distinct count of people who fall into two different dimensions.
One is called [Student Research Degree].[Is Research Degree Current].&[Yes]
The other is called [Student Research Degree].[Is Research Degree Complete].&[Yes]
If one or the other are Yes, or both, then I need to count the record.
If both are no, I can exclude it. I have a row counter measure called [Measures].[Student ID Distinct Count Hidden] already in place.
If I use just one element with the measure, I get the right answer, but if I try to cross join the other elements, I get a result of NULL.
eg
AGGREGATE(CROSSJOIN(
[Student Research Degree].[Is Research Degree Current].&[Yes]
,[Student Research Degree].[Is Research Degree Complete].&[Yes]
), [Measures].[Student ID Distinct Count Hidden])
I am aware that I can just land an extra value in the ETL, and have SQL do the work, and in the end this might be the solution. Is there a way of doing an OR statement on this sort of thing?
No, the TUPLE of &[YES], &[YES] doesn't create an OR situation, where I want [NO]s when the other is yes.
I started looking at a subtractive approach where I started with the ALL set, and removed the distinct count of invalid combinations in a tuple and subtracted that from the grand total. This approach did work, but ONLY because the data allowed for it. If a person could have been in multiple combinations, this wouldn't have worked.
I'm currently testing that approach with the rest of the cube. By all appearances this works perfectly, but I will go with ETL if any bugs or mismatches can be proven.

Derived Table Error: "The multi-part identifier could not be bound"

I'm having trouble getting the results I would like from the query I've built. The overall goal I'm trying to accomplish is to get the first odometer reading of the month and the last odometer reading of the month for a specific vehicle. I would then like to subtract the two to get total miles driven for that month. I figured a derived table with window functions would best help to accomplish this goal (see example SQL below).
SELECT
VEHICLE_ID2_FW
FROM
(SELECT
VEHICLE_ID2_FW,
LOCATION_CODE_FW,
MIN(ODOMETER_FW) OVER(PARTITION BY YEAR(DATE_FW), MONTH(DATE_FW)) AS MIN_ODO,
MAX(ODOMETER_FW) OVER(PARTITION BY YEAR(DATE_FW), MONTH(DATE_FW)) AS MAX_ODO
FROM
GPS_TRIPS_FW) AS G
I keep running into an issue where the derived table's query, by itself, runs and
works. However, when I bracket it in the FROM clause it shoots back an the error
The multi-part identifier could not be bound
Hoping that I could get some help figuring this out and maybe finding an overall better way to accomplish my goal. Thank you!
Odometers only increase (well, that should be true). So just use aggregation:
select VEHICLE_ID2_FW, year(date_fw), month(date_fw),
min(ODOMETER_FW), max(ODOMETER_FW),
max(ODOMETER_FW) - min(ODOMETER_FW) as miles_driven_in_month
from GPS_TRIPS_FW
group by VEHICLE_ID2_FW, year(date_fw), month(date_fw);
This answers the question that you asked. I don't think it solves your problem, though, because the total miles driven per month will not add up to the total miles driven. The issue are the miles driven between the last record at the end of the month and the first at the beginning of the next month.
If this is an issue, ask another question. Provide sample data, desired results, and an appropriate database tag.

SSAS Time Series, predict when something will fail

I would like to use SSAS and a TimeSeries Mining Structure to predict when the predictable value will reach a certain threshold.
For Example:
SELECT [Info Key],
PredictTimeSeries([Free Space], 200) as ForcastedSize
FROM [Drive Module Information]
WHERE ForcastedSize < 10000 --(<< this does not work)
This will tell me the date that it forecasts that the drive space will be below 10000.
How do I write an MDX query to accomplish this?
Thanks,
Brian
UPDATE 1:
I think I can accomplish it this way, with some limitations:
SELECT [Drive Module Information].[Info Key],
(SELECT *
FROM PredictTimeSeries([Drive Module Information].[Free Space], 5000) as [FUTURE]
) AS T
FROM [Drive Module Information]
WHERE
[Info Key] = 'MyMachine C:' AND
[Free Space] < 10000
The limitation is that I can only look X# of steps forward without getting crazy. Which is ok. I am ok with knowing that the drive will not fill up over the next week, or month.
I did not figure out how to use FILTER in this situation, and am still curious as to if there is a "What date will this predictable value be equal to this value".
UPDATE 2: I have come to the conclusion that SSAS was not meant to do this, so until I find out differently, I will mark icCube as the answer since he helped out.
MDX is not SQL, the where clause of MDX is not a real filter. As a quick introduction you can go through this MDX gentle Tutorial.
There is a MDX Filter function you can use.

Multiplying Quantity * Price in Calculated Member

I know MDX is used for much more sophisticated math, so please forgive the simplistic scenario, but this is one of my first Calculated members.
When I multiply Price x Quantity, the AS cube's data browser has the correct information in the leaf elements, but not in any of the parents. The reason seems to be that I want something like (1 * 2) + (2 * 3) + (4 * 5) and not (7 * 10) which think I am getting as a result of how the Sum is done on columns.
Is the IsLeaf expression intended to be used in these circumstances? Or is there another way? If so, are there any examples as simple as this I can see?
This Calculated member that I tried to create is just this:
[Measures].[Price]*[Measures].[Quantity]
The result for a particular line item (the leaf) is correct. But the results for, say, all of april, is an incredibly high number.
Edit:
I am now considering that this might be an issue regarding bad data. It would be helpful though if someone could just confirm that the above calculated member should be work under normal circumstances.
Here it is a blog post dealing with this particular problem: Aggregating the Result of an MDX Calculation Using Scoped Assignments.
For leaf level computations resulting in something that can then be summed, MDX is rather complex and slow.
The simplest way to do what you want to achieve would be to make this a normal measure, based on the Price x Quantity calculation defined in the data source view.