Check null columns MDX - mdx

I have MDX query:
SELECT NON EMPTY { [Measures].[Revenue] } ON COLUMNS, NON EMPTY {( [DimDates].[YearMonthNum].[YearMonthNum].ALLMEMBERS )}
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM ( SELECT ( { [TransactionsData].[FirstYearMonth].&[2020-01] } )
ON COLUMNS FROM ( SELECT ( { [TransactionsDataExtra].[Cluster].[All] } )
ON COLUMNS FROM ( SELECT ( { [TransactionsDataExtra].[Campaign].[All] } )
ON COLUMNS FROM ( SELECT ( { [TransactionsData].[RevenueGenerating].[All] } )
ON COLUMNS FROM ( SELECT ( { [TransactionsData].[Product].[All] } )
ON COLUMNS FROM ( SELECT ( { [TransactionsDataExtra].[Channel].[All] } )
ON COLUMNS FROM (SELECT ( { [TransactionsDataExtra].[Custom4].[All] } )
ON COLUMNS FROM (SELECT ( { [TransactionsDataExtra].[Custom5].[All] } )
ON COLUMNS FROM (SELECT ( { [TransactionsDataExtra].[Custom6].[All] } )
ON COLUMNS FROM (SELECT ( { [TransactionsData].[ClientId].&[2] } )
ON COLUMNS FROM [Model]))))))))))
WHERE ( [TransactionsDataExtra].[Channel].[All],
[TransactionsData].[Product].[All],
[TransactionsData].[RevenueGenerating].[All], [TransactionsDataExtra].[Campaign].[All],
[TransactionsData].[FirstYearMonth] <= ['2020-01'],
[TransactionsDataExtra].[Cluster].[All], [TransactionsData].[ClientId].&[2] )
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING,
FONT_NAME, FONT_SIZE, FONT_FLAGS
I want to get results where e.g. Custom6 is NULL, or Custom5 is NULL or both of them, or any other filter, or Custom5[NULL, Value]
but I've been struggling to find how to do that and where in the query add changes... I tried passing nothing like: [TransactionsDataExtra].[Cluster].&[] but that didn't return anything at all. Could anyone help me out?
I also looked up ISEMPTY but can't figure out how to add it..

Fo anyone struggling in the future like noob me use this:
[DataExtra].[Cluster].& instead [DataExtra].[Cluster].&[]
also, check this amazing Excel extension to view queries: https://olappivottableextensions.github.io/#view-pivottable-mdx

Related

MDX Combine two queries

I need two join two queries, I tried with members but it didn't work. I am new to MDX, please let me know if there a way of doing this. Error is due to list in the calculated member.
SELECT NON EMPTY { [RR TYPE].[Item].[Item].ALLMEMBERS * [Measures].[Unit Value] } ON COLUMNS,
NON EMPTY { ([FFS].[FFSCD].[FFSCD].ALLMEMBERS) } ON ROWS
FROM [GLCube]
WHERE ( [Location].[Site Name].&[Sandbox]
, [LT DT].[DATE HIERARCHY].[YEAR].&[2010]
,-{ [Ledger].[ID].&[A1],[Ledger].[ID].&[A2] ,[Ledger].[ID].&[A3]} )
SELECT NON EMPTY { [RT TYPE].[Item].[Item].ALLMEMBERS * [Measures].[Price Value] } ON COLUMNS,
NON EMPTY { ([FFS].[FFSCD].[FFSCD].ALLMEMBERS) } ON ROWS
FROM (SELECT [CCTYPE].[Desc].&[FCD] ON COLUMNS
FROM [GLCube])
WHERE ( [Location].[Site Name].&[Sandbox]
, [LT DT].[DATE HIERARCHY].[YEAR].&[2010])
Combined query
WITH MEMBER [Measures].[Unit Value]] AS
(-{[Ledger].[ID].&[A1],[Ledger].[ID].&[A2] ,[Ledger].[ID].&[A3]},[Measures].[Unit Value])
MEMBER [Measures].[Price Value] AS
( [CCTYPE].[Desc].&[FCD],[Measures].[Price Value] )
SELECT NON EMPTY {[Measures].[Unit Value],[Measures].[Price Value]} ON COLUMNS,
NON EMPTY { ([FFS].[FFSCD].[FFSCD].ALLMEMBERS} ON ROWS
FROM [GLCube]
WHERE ( [Location].[Site Name].&[Sandbox]
, [LT DT].[DATE HIERARCHY].[YEAR].&[2010])
Expected Output
WITH
MEMBER [Measures].[Filtered Unit Value] as
Aggregate(
-{ [Ledger].[ID].&[A1],[Ledger].[ID].&[A2] ,[Ledger].[ID].&[A3]},
[Measures].[Unit Value]
)
SELECT NON EMPTY
{
[RR TYPE].[Item].[Item].ALLMEMBERS
* {[RT TYPE].[Item].[All]}
* { [CCTYPE].[Desc].[All]}
* [Measures].[Filtered Unit Value]
}
+
{
{[RR TYPE].[Item].[All]}
* [RT TYPE].[Item].[Item].ALLMEMBERS
* { [CCTYPE].[Desc].&[FCD]}
* [Measures].[Price Value]
}
ON COLUMNS,
NON EMPTY { ([FFS].[FFSCD].[FFSCD].ALLMEMBERS) } ON ROWS
FROM [GLCube]
WHERE ( [Location].[Site Name].&[Sandbox]
, [LT DT].[DATE HIERARCHY].[YEAR].&[2010]
)

MDX query to join two different dimension members

I have below select statement which I want to convert into cube members and calculate the sum.
SELECT NON EMPTY { [Measures].[volume] } ON COLUMNS, NON EMPTY { ([par_Account].[Account].[Account].ALLMEMBERS * [Product].[Hierarchy].[Local product var].ALLMEMBERS ) } ON ROWS FROM ( SELECT ( { [Product].[Hierarchy].[local product Group].&[-33554010354150679].&[-952789350662854159].&[8639428195894987853] } ) ON COLUMNS FROM ( SELECT ( { [Time].[Financial Period].&[-8540082585673218205] } ) ON COLUMNS FROM ( SELECT ( { [Market].[Market].&[-3381499019102906042] } ) ON COLUMNS FROM [cube]))) WHERE ( [Market].[Market].&[-3381499019102906042], [Time].[Financial Period].&[-8540082585673218205] )
Please help me with this.
I guess this is what you are looking for. However its always nice to explain what your problem is, or perhaps provide screenshot.
SELECT
NON EMPTY { [Measures].[volume] } ON COLUMNS,
NON EMPTY {
(
[Market].[Market].&[-3381499019102906042] *
[Time].[Financial Period].&[-8540082585673218205] *
{ [Product].[Hierarchy].[local product Group].&[-33554010354150679].&[-952789350662854159].&[8639428195894987853] } *
[par_Account].[Account].[Account].ALLMEMBERS *
[Product].[Hierarchy].[Local product var].ALLMEMBERS
)
} ON ROWS
from [cube]

Combine different hierarchy levels using MDX Query

1.Description
Now I have two mdx query, the only differences is the ON ROWS settings.
Here is each query and its results.
Query 1 :
SELECT
NON EMPTY
{
[PLOwner].[PLOwner].Members
}
ON ROWS
,
NON EMPTY
Crossjoin(
{
[InfoType].[InfoType].[Risk_RecoveryJTDTable],
[InfoType].[InfoType].[Equivalent_Notional],
[InfoType].[InfoType].[Risk_SPC],
[InfoType].[InfoType].[Risk_PSM],
[InfoType].[InfoType].[Risk_PV10],
[InfoType].[InfoType].[Notional],
[InfoType].[InfoType].[Notional_IMM],
[InfoType].[InfoType].[PnL],
[InfoType].[InfoType].[TomorrowPnL],
[InfoType].[InfoType].[RollPnL],
[InfoType].[InfoType].[RollDownPnL],
[InfoType].[InfoType].[Risk_JTD],
[InfoType].[InfoType].[Risk_Raw_KC],
[InfoType].[InfoType].[Risk_RR],
[InfoType].[InfoType].[FundingPnLWCOF],
[InfoType].[InfoType].[FundingPnLRR],
[InfoType].[InfoType].[FundingPnLSHW],
[InfoType].[InfoType].[FundingPnLBox],
[InfoType].[InfoType].[FundingPnLInterest]
}
,
{
DrillDownLevel([Category].[ALL].[AllMember])
}
,
{
DrillDownLevel([Label1].[ALL].[AllMember])
}
,
{
DrillDownLevel([IsError].[ALL].[AllMember])
}
)
ON COLUMNS
FROM
[UnityRiskCube]
WHERE
(
[Measures].[Risk.SUM],
[BusinessGroup].[BusinessGroup].[AeJ Flow Credit],
[Context].[ContextId].[official:Live]
)
Result 1: (I use Excel to show String[][] result from Pivot)
Result 1-click to see the image
Query 2 :
SELECT
NON EMPTY
Crossjoin(
{
[PLOwner].[PLOwner].Members
}
,
{
[PLGroup].[PLGroup].Members
}
)
ON ROWS
,
NON EMPTY
Crossjoin(
{
[InfoType].[InfoType].[Risk_RecoveryJTDTable],
[InfoType].[InfoType].[Equivalent_Notional],
[InfoType].[InfoType].[Risk_SPC],
[InfoType].[InfoType].[Risk_PSM],
[InfoType].[InfoType].[Risk_PV10],
[InfoType].[InfoType].[Notional],
[InfoType].[InfoType].[Notional_IMM],
[InfoType].[InfoType].[PnL],
[InfoType].[InfoType].[TomorrowPnL],
[InfoType].[InfoType].[RollPnL],
[InfoType].[InfoType].[RollDownPnL],
[InfoType].[InfoType].[Risk_JTD],
[InfoType].[InfoType].[Risk_Raw_KC],
[InfoType].[InfoType].[Risk_RR],
[InfoType].[InfoType].[FundingPnLWCOF],
[InfoType].[InfoType].[FundingPnLRR],
[InfoType].[InfoType].[FundingPnLSHW],
[InfoType].[InfoType].[FundingPnLBox],
[InfoType].[InfoType].[FundingPnLInterest]
}
,
{
DrillDownLevel([Category].[ALL].[AllMember])
}
,
{
DrillDownLevel([Label1].[ALL].[AllMember])
}
,
{
DrillDownLevel([IsError].[ALL].[AllMember])
}
)
ON COLUMNS
FROM
[UnityRiskCube]
WHERE
(
[Measures].[Risk.SUM],
[BusinessGroup].[BusinessGroup].[AeJ Flow Credit],
[Context].[ContextId].[official:Live]
)
Result 2: (I use Excel to show String[][] result from Pivot)
Result 2-click to see the image
2.Question
How can i get these data together using one Mdx query?
Thanks a lot.
I think you can use the ALL member of the PLGroup hierarchy to be able to combine - you have no choice in that there will need to be the same dimensionality for both:
SELECT
NON EMPTY
{
[PLOwner].[PLOwner].Members
*[PLGroup].[PLGroup].[All] //<< or this may be [PLGroup].[All]
,
[PLOwner].[PLOwner].Members
*[PLGroup].[PLGroup].Members
}
ON ROWS
,
NON EMPTY
Crossjoin(
{
[InfoType].[InfoType].[Risk_RecoveryJTDTable],
[InfoType].[InfoType].[Equivalent_Notional],
[InfoType].[InfoType].[Risk_SPC],
[InfoType].[InfoType].[Risk_PSM],
[InfoType].[InfoType].[Risk_PV10],
[InfoType].[InfoType].[Notional],
[InfoType].[InfoType].[Notional_IMM],
[InfoType].[InfoType].[PnL],
[InfoType].[InfoType].[TomorrowPnL],
[InfoType].[InfoType].[RollPnL],
[InfoType].[InfoType].[RollDownPnL],
[InfoType].[InfoType].[Risk_JTD],
[InfoType].[InfoType].[Risk_Raw_KC],
[InfoType].[InfoType].[Risk_RR],
[InfoType].[InfoType].[FundingPnLWCOF],
[InfoType].[InfoType].[FundingPnLRR],
[InfoType].[InfoType].[FundingPnLSHW],
[InfoType].[InfoType].[FundingPnLBox],
[InfoType].[InfoType].[FundingPnLInterest]
}
,
{
DrillDownLevel([Category].[ALL].[AllMember])
}
,
{
DrillDownLevel([Label1].[ALL].[AllMember])
}
,
{
DrillDownLevel([IsError].[ALL].[AllMember])
}
)
ON COLUMNS
FROM
[UnityRiskCube]
WHERE
(
[Measures].[Risk.SUM],
[BusinessGroup].[BusinessGroup].[AeJ Flow Credit],
[Context].[ContextId].[official:Live]
)

MDX - multiple filters on different dimension with OR condition

I have a problem with MDX querying.
I have one measure WEIGHT and two dimensions DESTINATION and SOURCE with the same attributes: NAME and TYPE.
I want to return:
SUM of WEIGHT
where
DESTINATION.TYPE="A"
**OR**
SOURCE.TYPE="B"
**AND**
(DESTINATION.TYPE **<>** SOURCE.TYPE)
If try this:
SELECT NON EMPTY {
[Measures].[Weight]
}
ON COLUMNS,
NON EMPTY {
([Source].[Name].[Name].ALLMEMBERS * [Destination].[Name].[Name].ALLMEMBERS )
}
ON ROWS
FROM
( SELECT ( { [Source].[Type].&[A] } ) ON COLUMNS FROM ( SELECT ( { [Destination].[Type].&[B] } )
ON COLUMNS FROM [CUBE])) WHERE ( [Destination].[Type].&[B], [Source].[Type].&[A] )
But it doesn't work.
In SQL it look like
Select source.name, destination.name, sum(weight) from cube
where
(source.type = "A" or destination.type = "b")
and
(source.type <> destination.type)
group by source.name, destination.name, source.type, destination.type
Your From section is a bit messy. Try the following:
SELECT
NON EMPTY { [Measures].[Weight] } ON COLUMNS,
NON EMPTY { [Source].[Name].[Name].ALLMEMBERS * [Destination].[Name].[Name].ALLMEMBERS } ON ROWS
FROM [CUBE]
WHERE ( {[Destination].[Type].&[B]} * {[Source].[Type].[All]} + {[Destination].[Type].[All]} * {[Source].[Type].&[A]} )

How do you get the total rows in an MDX query to use for paging?

I am attempting to implement paging to large datasets in MDX (SSAS).
I have the following to retrieve paged data which works fine:
SELECT
{
[Measures].[Mesasure1],
[Measures].[Measure2]
} ON COLUMNS,
SUBSET
(
ORDER
(
{
(
[Item].[Category].ALLMEMBERS
)
}, NULL, BASC
), 10, 50 --10 = start index, 50 = returned roes
)
ON ROWS
FROM ( SELECT ( { [Time].[Date].&[2012-04-15T00:00:00]:[Time].[Date].&[2012-04-20T00:00:00] } ) ON COLUMNS
FROM [DataMartPerformance]
))
However I cannot for the life of me find anywhere on the internet that helps explain how to get the total rows available. Do I do it in a seperate query? If so how?
Or can I wrap it into this one query somehow?
Similar to how you'd do TSQL paging, you'll need to run another query to count the total elements. You may have to tinker with this depending on how you've done your original query, but I use something like:
WITH
MEMBER [Measures].[ElementCount] AS
{
NONEMPTY
(
{
[Item].[Category].ALLMEMBERS *
{ [Time].[Date].&[2012-04-15T00:00:00]:[Time].[Date].&[2012-04-20T00:00:00] }
},
{
[Measures].[Mesasure1],
[Measures].[Measure2]
}
)
}.COUNT
SELECT
{
[Measures].[ElementCount]
}
ON COLUMNS
FROM
[DataMartPerformance]
For filtering, you can do dimension filters by using an exists against your dimension attributes:
WITH
MEMBER [Measures].[ElementCount] AS
{
NONEMPTY
(
EXISTS
(
{
[Item].[Category].ALLMEMBERS *
{ [Time].[Date].&[2012-04-15T00:00:00]:[Time].[Date].&[2012-04-20T00:00:00] }
},
{
[Dimension].[Attribute].[FilterByThisAttribute]
}
),
{
[Measures].[Mesasure1],
[Measures].[Measure2]
}
)
}.COUNT
SELECT
{
[Measures].[ElementCount]
}
ON COLUMNS
FROM
[DataMartPerformance]
I haven't got to writing the measure value filters yet, I need to do that next for my own MDX paging constructor...
Please try this:
WITH
SET MySet As
(
NONEMPTY (
[AU Time Sale Hour].[Hour Key].[Hour Key]
* [Dim Country].[Country Key].[Country Key]
)
)
Member [Measures] .cnt AS MySet.Count
select [Measures] .cnt on Columns
from [Me Stats DW Fact Sales]
where (
{[Dim Visa].[Visa Key].&[2067],[Dim Visa].[Visa Key].&[2068] },
[AU Time Sale Date].[Date].&[20091120]:[AU Time Sale Date].[Date].&[20091125]
)