Merge rows in mdx - mdx

I have some MDX:
SELECT
NON EMPTY {
[Dim Investigation Report].[ID].children *
[Dim Energy Object Full].[Name].children} ON ROWS,
NON EMPTY {[Measures].[ID Distinct Count]} ON COLUMNS
FROM [acts]
It returns:
003022 2604171226005 Object1 1
003022 2604171226005 Object2 1
How can I change the request to have result like this:
003022 2604171226005 Object1 Object2 1
Thank you.

Related

MDX: Distinct Count of members summarized by another dimension

From my cube, I am trying to get a distinct count of all non-empty [ID].[FullID]s but summarized by [Underlying].
I know that, for example, there are two IDs for [Underlying].[Underlying1] at this particular WHERE slice and I can see this by running the below MDX query, which clearly gives me a row for each (but a zero count?):
Results:
Underlying | FullID | CountOf
------------------------------
Underlying1 | ID1 | 0
Underlying1 | ID2 | 0
...
Code:
WITH
MEMBER CountOf AS
DistinctCount([ID].[FullID].Children)
SELECT
NON EMPTY {[Underlying].Children * [ID].[FullID].Children
} ON ROWS,
NON EMPTY {CountOf
} ON COLUMNS
FROM [MyCube]
WHERE ([Time].&[2018-11-27T00:00:00],
[Factor].[FactorName].[FACTOR1],
[Factor].[FactorType].[FACTORTYPE1]
[Location].[Location1]
)
However when I remove the * [ID].[FullID].Children I don't get what would like:
What I want:
Underlying | CountOf
---------------------
Underlying1 | 2
...
What I get:
Underlying | CountOf
---------------------
Underlying1 | 24
...
There is clearly something else going on here to give me a 24 count, but I cannot figure it out...
You are getting 24 because you measure is counting the members in [ID].[FullID].Children. What i understand is that you want to count the number of [ID].[FullID] who have a fact value availabe against them for [Underlying].Children. So your code should be like this
WITH
MEMBER CountOf AS
Count(
nonempty(([Underlying].currentmember,[ID].[FullID].Children),
[Measures].[ConnectingMeasure])
)
SELECT NON EMPTY {[Underlying].Children } ON ROWS,
NON EMPTY {CountOf} ON COLUMNS
FROM [MyCube]
WHERE ([Time].&[2018-11-27T00:00:00],[Factor].[FactorName].[FACTOR1],
[Factor].[FactorType].[FACTORTYPE1],[Location].[Location1]
)
Here is a sample of what you want to do in adventureworks. I am trying to count all Promotion, that are present for a product based on the internet sales data.
WITH
MEMBER CountOf AS
count(nonempty( ([Product].[Product].currentmember, [Promotion].[Promotion].children) ,[Measures].[Internet Sales Amount]))
SELECT
NON EMPTY {CountOf} ON COLUMNS,
NON EMPTY {
([Product].[Product].Children )
} ON ROWS
FROM [Adventure Works]
//Base query to understand what is counted
WITH
MEMBER CountOf AS
Count(nonempty( ([Product].[Product].currentmember, [Promotion].[Promotion].children) ,[Measures].[Internet Sales Amount]))
SELECT
NON EMPTY [Measures].[Internet Sales Amount] ON COLUMNS,
NON EMPTY {
([Product].[Product].Children,[Promotion].[Promotion].children )
} ON ROWS
FROM [Adventure Works]

How to get rid of empty cells when combining measures and kpi goals in MDX Query

I have this issue with an MDX query where the NON EMPTY clause isn’t working as I expected after adding KPI goals, trends and status to the query.
The basic query looks like this
SELECT
NON EMPTY({[Measure1], [Measure2], KPIValue('MyKpi')})
ON COLUMNS,
NON EMPTY [Dim Country].[Name].[Name].ALLMEMBERS ON ROWS
FROM [BIA CO]
returning something like this, which is fine:
Measure1 Measure2 MyKpi
Canada 7977 4487 3231
USA 6 14 6
UK 442 1179 180
Problems comes when I add KPI goal, trend and status:
SELECT
NON EMPTY({[Measure1], [Measure2], KPIValue('MyKpi'), KPIGoal('MyKpi'), KPIStatus('MyKpi'), KPITrend('MyKpi')})
ON COLUMNS,
NON EMPTY [Dim Country].[Name].[Name]ALLMEMBERS ON ROWS
FROM [BIA CO]
Which returns something like:
Measure1 Measure2 MyKpi MyKpi Goal MyKpi Status MyKpi Trend
Mexico (null) (null) (null) 40300 -1 -1
Cuba (null) (null) (null) 40300 -1 -1
Canada 7977 4487 3231 40300 -1 1
Portugal (null) (null) (null) 40300 -1 -1
China (null) (null) (null) 40300 -1 -1
USA 6 14 6 40300 -1 1
UK 442 1179 180 40300 -1 1
How can I get rid of all those rows with nulls except for the goal, status and trend?
Simply add the Non-empty behavior to your KPIs. If you set Measure1 you'll filter out all empty tuples. It'll inherit the non-empty behavior from the Measure1. Also you may return the the following set on rows with similar logic (the output will be the same):
NonEmpty([Dim Country].[Name].[Name].ALLMEMBERS,[Measures].[Measure1]) on rows
I had a similar problem and this is what I did. In my case I had no control over the cube design. I'm not an expert so wait for some experienced feedback before using it.
WITH
MEMBER [KPIValue(ReservaKPI)] as KPIValue('ReservaKPI')
MEMBER [KPIGoal(ReservaKPI)] as CASE WHEN ISEMPTY([KPIValue(ReservaKPI)]) THEN NULL ELSE KPIGoal('ReservaKPI') END
MEMBER [KPIStatus(ReservaKPI)] as CASE WHEN ISEMPTY([KPIValue(ReservaKPI)]) THEN NULL ELSE KPIStatus('ReservaKPI') END
MEMBER [KPITrend(ReservaKPI)] as CASE WHEN ISEMPTY([KPIValue(ReservaKPI)]) THEN NULL ELSE KPITrend('ReservaKPI') END
SELECT
NON EMPTY({[Cant Adultos], [Cant Noches], [KPIValue(ReservaKPI)], [KPIGoal(ReservaKPI)], [KPIStatus(ReservaKPI)], [KPITrend(ReservaKPI)]})
ON COLUMNS,
NON EMPTY [Dim Mun].[NOMBRE].[NOMBRE].ALLMEMBERS ON ROWS
FROM [BIA CO]
I sometimes like to use the HAVING clause like this maybe:
SELECT
NON EMPTY
{
[Measure1]
,[Measure2]
,KPIValue('MyKpi')
,KPIGoal('MyKpi')
,KPIStatus('MyKpi')
,KPITrend('MyKpi')
} ON COLUMNS
,NON EMPTY
[Dim Country].[Name].[Name].ALLMEMBERS HAVING
(NOT IsEmpty([Measure1])) AND (NOT IsEmpty([Measure2])) ON ROWS
FROM [BIA CO];
But you could move that logic into a WITH clause as suggested by #user1998299 - I'd probably do a custom set:
WITH
SET [SmallSet] AS
NonEmpty
(
NonEmpty
(
[Dim Country].[Name].[Name].ALLMEMBERS
,[Measure1]
)
,[Measure2]
)
SELECT
NON EMPTY
{
[Measure1]
,[Measure2]
,KPIValue('MyKpi')
,KPIGoal('MyKpi')
,KPIStatus('MyKpi')
,KPITrend('MyKpi')
} ON COLUMNS
,NON EMPTY
[SmallSet] ON ROWS
FROM [BIA CO];

Not allow any null values in resultset MDX

I want to exclude any rows where there is a null value in my MDX query. Sounds simple enough:
SELECT
NON EMPTY{
....
}
ON 0
etc...
However, one of my columns has values even though the other ones only contain null vales.
Example:
Area | ComputerSales | Areadirector
WA (Null) Steve
NY 21312 Mary
How do I remove the first row, where there is a (null) value?
You could use HAVING
SELECT
{
[Measures].[Computer Sales]
,[Measures].[Areadirector]
} ON 0
,[AreaDimension].[Area].[Area] HAVING
(NOT
IsEmpty([Measures].[Computer Sales])) ON 1
FROM [YourCube];
Or make the set in a WITH clause first:
WITH
SET [S] AS
NonEmpty
(
[AreaDimension].[Area].[Area]
,[Measures].[Computer Sales]
)
SELECT
{
[Measures].[Computer Sales]
,[Measures].[Areadirector]
} ON 0
,[S] ON 1
FROM [YourCube];
Second approach is probably more efficient.
You can use for example FILTER and ISEMPTY function
SELECT
[Measures].[Fac Count] on 0,
FILTER(
[Time].[Date Key].children,
NOT ISEMPTY([Measures].[Fac Count])
)
on 1
FROM
[Test]
this simple query returns only date keys that Fac Count measure has non empty value.

select data from olap MDX query

Please help to understand how MDX query works.
I have connected to cube using excel and construct a mdx query. In short finally I need to get the table like this:
12.01.2015
+-------+-------+-------+-----+-------+------
| 00:00 | 01:00 | 02:00 | ... | 23:00 | TOTAL
--------+-------+-------+-------+-----+-------+------
Ivan | null | 3 | null | ... | 12 | 38
Pert | 3 | 8 | null | ... | null | 125
Sidor |
We see the Date, Time (hour), FIO (Ivan, Petr etc) and values.
The cube has dimensions: Dim Date, Dim Hour, Dim Users
I trying to get MDX query from excel but I cant understand how to modify it to get result I need. Here is the request (formatted):
SELECT NON EMPTY
CrossJoin(
Hierarchize(
DrilldownMember(
{
{
DrilldownMember(
{
{
DrilldownLevel
(
{[Dim Date].[Даты YMD].[All]}
)
}
},
{[Dim Date].[Даты YMD].[Year Name].&[2015]}
)
}
},
{[Dim Date].[Даты YMD].[Year Name].&[2015].&[5]}
)
),
Hierarchize(
{
DrilldownLevel(
{[Dim Hour].[Hour Key].[All]}
)
}
))
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,
[Dim Date].[Даты YMD].[Date Key].[Month Name],[Dim Date].[Даты YMD].[Date Key].[Year Name] ON COLUMNS ,
NON EMPTY
Hierarchize(
{
DrilldownLevel(
{[Dim Users].[FIO].[All]}
)
}
)
DIMENSION PROPERTIES PARENT_UNIQUE_NAME ON ROWS FROM
(
SELECT ({[Dim Date].[Даты YMD].[Year Name].&[2015].&[5]}
)
ON COLUMNS
FROM [Dwh Sorting])
WHERE ([Measures].[Fact Table Count]) CELL PROPERTIES VALUE,
FORMAT_STRING,
LANGUAGE,
BACK_COLOR,
FORE_COLOR,
FONT_FLAGS
It gets data for May 2015. My goal is to get a long table (with a lot of columns) like I showed. With one or more months.
Excel code that is autogenerated adds a lot of extra "bits".
Getting rid of the extra bits I'm guessing at something like the below. This script should give you lots of columns - assuming data for every hour in 2015 you should end up with 24 columns for every day in 2015!
The reason I say "guessing" as we do not know the hiearchical structure of your cube:
SELECT
NON EMPTY
Descendants
(
[Dim Date].[Даты YMD].[Year Name].&[2015]
,[Dim Date].[Даты YMD].[Date] //<<this assumes there is a level in Dim date called Date
)
*
{[Dim Hour].[Hour Key].MEMBERS} ON COLUMNS
,NON EMPTY
[Dim Users].[FIO].MEMBERS ON ROWS
FROM [Dwh Sorting]
WHERE
[Measures].[Fact Table Count];
If you need just the hours for a range of dates then try the : operator. You will not need to apply the Descendants function in this case:
SELECT
NON EMPTY
(
[Dim Date].[Даты YMD].[Date Key].[2014-01-02]
:
[Dim Date].[Даты YMD].[Date Key].[2015-02-10]
)
*
{[Dim Hour].[Hour Key].MEMBERS} ON COLUMNS
,NON EMPTY
[Dim Users].[FIO].MEMBERS ON ROWS
FROM [Dwh Sorting]
WHERE
[Measures].[Fact Table Count];

MDX: Showing a zero count for non-existing members

I'm still a newbie at MDX, so maybe this will be a simple question.
I want to do something like see sales revenue by product: more specifically, products are classified in "classes" (where class can be A,B or C), so I want to see the amount of sales of class A products, class B and so on. If the Dimension "Product" has one Hierarchy "Classification" with level "Class", suppose the MDX query, for the sake of simplicity, is as follows:
SELECT
[Measures].[Sales] on COLUMNS,
[Product].[Classification].[Class].members on ROWS
FROM [Cube]
Problem is, if there's no record with class='C',for example, in Data table Product, there will be no member 'C', right? In that case, I'd like to show a zero count for that. So, instead of having:
| Sales
A 1000
B 200
I'd like:
| Sales
A 1000
B 200
C 0
Any help?
Thanks in advance!
Problem is, if there's no record with class='C',for example, in Data
table Product, there will be no member 'C', right?
As your select does not contain NON EMPTY ... ON ROWS, then 'C' should be returned with an empty cell as its 'Sales' value. It is possible that your 'client' tool is then ignoring it.
What you can do is define a calculated measure using the CoalesceEmpty() function to return a ZERO value instead of empty :
WITH
MEMBER [Measures].[Sales - X] as
CoalesceEmpty( ( [Measures].[Sales] ).Value, 0 )
SELECT
[Measures].[Sales - X] on COLUMNS,
[Product].[Classification].[Class].members on ROWS
FROM [Cube]