Essbase MDX queries not matching - mdx

I am using a BI tool that auto-generates MDX code for an Essbase data source. I am running two queries that should bring back the same numbers, but I get different numbers.
The first query brings back results by month for 12 months of the year and produces incorrect results:
SELECT
NON EMPTY
{
[Jan]
,[Feb]
,[Mar]
,[Apr]
,[May]
,[Jun]
,[Jul]
,[Aug]
,[Sep]
,[Oct]
,[Nov]
,[Dec]
}
DIMENSION PROPERTIES
[MEMBER_UNIQUE_NAME]
,[MEMBER_CAPTION]
,[GEN_NUMBER]
,[LEVEL_NUMBER]
ON COLUMNS
,NON EMPTY
Descendants
(
[ABOVE]
,[ABOVE].Level
,AFTER
)
DIMENSION PROPERTIES
[MEMBER_UNIQUE_NAME]
,[MEMBER_CAPTION]
,[GEN_NUMBER]
,[LEVEL_NUMBER]
ON ROWS
FROM [F_IntPrf].[F_IntPrf]
WHERE
(
[ALL_TERRITORY]
,[ALL_PS_BUS_AFF]
,[ALL_PS_BUS]
,[Input Currency]
,[MayFC]
,[FY17]
,[Forecast]
,[USDRep]
);
The second query shows the results for January only, and produces the correct results :
SELECT
NON EMPTY
Descendants
(
[ABOVE]
,[ABOVE].Level
,AFTER
)
DIMENSION PROPERTIES
[MEMBER_UNIQUE_NAME]
,[MEMBER_CAPTION]
,[GEN_NUMBER]
,[LEVEL_NUMBER]
ON COLUMNS
FROM [F_IntPrf].[F_IntPrf]
WHERE
(
[Jan]
,[ALL_TERRITORY]
,[ALL_PS_BUS_AFF]
,[ALL_PS_BUS]
,[Input Currency]
,[MayFC]
,[FY17]
,[Forecast]
,[USDRep]
);
What am I doing wrong in the first query ?
Thank you!

To focus in on the problem I would start by comparing two very simple queries such as these two:
SELECT
NON EMPTY
{
[Jan]
}
ON COLUMNS
,NON EMPTY
Descendants
(
[ABOVE]
,[ABOVE].Level
,AFTER
)
ON ROWS
FROM [F_IntPrf].[F_IntPrf]
WHERE
(
[ALL_TERRITORY]
);
versus this...
SELECT
NON EMPTY
Descendants
(
[ABOVE]
,[ABOVE].Level
,AFTER
)
ON COLUMNS
FROM [F_IntPrf].[F_IntPrf]
WHERE
(
[Jan]
,[ALL_TERRITORY]
);
Do they match? If they do then slowly add in the other dimensions until they don't match and then you know where the problem is

Related

custom count measure runs forever MDX

So this question goes off the one here
I've been trying to do a similar count measure and I did the suggested solution but it's still running.... and it's been more than 30 minutes with no results, while without that it runs in under a minute. So am I missing something? Any guidance would help. Here is my query:
WITH
MEMBER [Measures].[IteractionCount] AS
NONEMPTY
(
FILTER
(
([DimInteraction].[InteractionId].[ALL].Children,
[Measures].[Impression Count]),
[DimInteraction].[Interaction State].&[Enabled]
)
).count
SELECT
(
{[Measures].[IteractionCount],
[Measures].[Impression Count]}
)
ON COLUMNS,
(
([DimCampaign].[CampaignId].[CampaignId].MEMBERS,
[DimCampaign].[Campaign Name].[Campaign Name].MEMBERS,
[DimCampaign].[Owner].[Owner].MEMBERS)
,[DimDate].[date].[date].MEMBERS
)
ON ROWS
FROM
(
SELECT
(
{[DimDate].[date].&[2020-05-06T00:00:00] : [DimDate].[date].&[2020-05-27T00:00:00]}
)
ON COLUMNS
FROM [Model]
)
WHERE
(
{[DimCampaign].[EndDate].&[2020-05-27T00:00:00]:NULL},
[DimCampaign].[Campaign State].&[Active],
{[DimInteraction].[End Date].&[2020-05-27T00:00:00]:NULL}//,
//[DimInteraction].[Interaction State].&[Enabled]
)
I don't know if FILTER is affecting it in any way but I tried it with and without and it still runs forever. I do need it specifically filtered to [DimInteraction].[Interaction State].&[Enabled]. I have also tried to instead filter to that option in the WHERE clause but no luck
Any suggestions to optimize this would be greatly appreciated! thanks!
UPDATE:
I end up using this query to load data into a python dataframe. Here is my code for that. I used this script for connecting and loading the data. I had to make some edits to it though to use windows authentication.
ssas_api._load_assemblies() #this uses Windows Authentication
conn = ssas_api.set_conn_string(server='server name',db_name='db name')
df = ssas_api.get_DAX(connection_string=conn, dax_string=query))
The dax_string parameter is what accepts the dax or mdx query to pull from the cube.
Please try this optimization:
WITH
MEMBER [Measures].[IteractionCount] AS
SUM
(
[DimInteraction].[InteractionId].[InteractionId].Members
* [DimInteraction].[Interaction State].&[Enabled],
IIF(
IsEmpty([Measures].[Impression Count]),
Null,
1
)
)
SELECT
(
{[Measures].[IteractionCount],
[Measures].[Impression Count]}
)
ON COLUMNS,
(
([DimCampaign].[CampaignId].[CampaignId].MEMBERS,
[DimCampaign].[Campaign Name].[Campaign Name].MEMBERS,
[DimCampaign].[Owner].[Owner].MEMBERS)
,[DimDate].[date].[date].MEMBERS
)
PROPERTIES MEMBER_CAPTION
ON ROWS
FROM
(
SELECT
(
{[DimDate].[date].&[2020-05-06T00:00:00] : [DimDate].[date].&[2020-05-27T00:00:00]}
)
ON COLUMNS
FROM [Model]
)
WHERE
(
{[DimCampaign].[EndDate].&[2020-05-27T00:00:00]:NULL},
[DimCampaign].[Campaign State].&[Active],
{[DimInteraction].[End Date].&[2020-05-27T00:00:00]:NULL}//,
//[DimInteraction].[Interaction State].&[Enabled]
)
CELL PROPERTIES VALUE
If that doesn’t perform well the please describe the number of rows returned by your query when you comment out IteractionCount (sic) from the columns axis. And please describe how many unique InteractionId values you have.

Results of MDX query against missing partition - Tabular 2012

UPDATE: the resolution was to do a process full at the database level instead of at the partition level.
I am trying to understand the behavior I am observing with a query a Tabular model. I partition by quarter, so when I built a new "current quarter" partition at the start of this quarter, the partition that used to contain 2016-Q4 was overwritten with 2017-Q1. Then when I ran my MDX query against the Tabular model filtering on the date dimension for 2016-Q4, instead of returning nothing like I would have expected, it returned data from the oldest partition 2014-Q1. It is like instead of returning no data, it decides to return the "first record" for that dimension (in this case all dates where 07/01/2014). Every other dimension I was filtering on still performed as expected.
Does anybody have any ideas as to why it behaves this way? FYI, I have tried restructuring my MDX statement a couple different ways:
SELECT
NON EMPTY { [Measures].[Measure1]} ON COLUMNS,
NON EMPTY { ([Dimension].[Dimension1])} DIMENSION PROPERTIES member_caption, member_unique_name ON ROWS
FROM [Model] WHERE ([Dimension].[Dimension2].&[Value], [DateDimension].[DateDimension].&[Value1] : [DateDimension].[DateDimension].&[Value2])
AND
SELECT
NON EMPTY { [Measures].[Measure1]} ON COLUMNS,
NON EMPTY { ( except([Dimension].[Dimension1].members,[Dimension].[Dimension1].[all]))} DIMENSION PROPERTIES member_caption, member_unique_name ON ROWS
FROM ( SELECT ( [Dimension].[Dimension1].&[Value] ) ON COLUMNS
FROM ( SELECT ( [Dimension].[Dimension2].&[Value] ) ON COLUMNS
FROM ( SELECT ( [DateDimension].[DateDimension].&[Value1] : [DateDimension].[DateDimension].&[Value2] ) ON COLUMNS
FROM [Model])))
Edit: added example of actual MDX
SELECT
NON EMPTY { [Measures].[ConvertedNetRevenue],
[Measures].[LoadConvertedNetRevenue],
[Measures].[OrderConvertedNetRevenue],
[Measures].[TotalOrderBrokerageCount],
[Measures].[TotalLoadBrokerageCount]
} ON COLUMNS,
NON EMPTY {
(
except([BrokerageQuery].[KeyBranch].members,[BrokerageQuery].[KeyBranch].[all]),
except([BrokerageQuery].[LoadNumber].members,[BrokerageQuery].[LoadNumber].[all]),
except([BrokerageQuery].[CustomerOrderNumber].members,[BrokerageQuery].[CustomerOrderNumber].[all]),
except([BrokerageQuery].[BranchName].members,[BrokerageQuery].[BranchName].[all]),
except([BrokerageQuery].[BranchCode].members,[BrokerageQuery].[BranchCode].[all]),
except([BrokerageQuery].[BranchRoleDescription].members,[BrokerageQuery].[BranchRoleDescription].[all]),
except([BrokerageQuery].[ModeDescription].members,[BrokerageQuery].[ModeDescription].[all]),
except([BrokerageQuery].[ServiceTypeDescription].members,[BrokerageQuery].[ServiceTypeDescription].[all]),
except([BrokerageQuery].[SystemDisplayName].members,[BrokerageQuery].[SystemDisplayName].[all]),
except([BrokerageQuery].[IsPartialFinLock].members,[BrokerageQuery].[IsPartialFinLock].[all]),
except([BrokerageQuery].[KeyDate_Financial].members,[BrokerageQuery].[KeyDate_Financial].[all])
)
} DIMENSION PROPERTIES member_caption, member_unique_name ON ROWS
FROM ( SELECT
(
{
[dimCurrency].[CurrencyCode].&[USD]
}
) ON COLUMNS
FROM ( SELECT
(
{
{
[BrokerageQuery].[KeyBranch].[10279]
}
}
) ON COLUMNS
FROM ( SELECT
(
[BrokerageQuery].[KeyDate_Financial].&[20161106] :
[BrokerageQuery].[KeyDate_Financial].&[20161106]
) ON COLUMNS
FROM [Brokerage])))
Instead of processing our partitions individually (at the beginning of each quarter when re-partitioning occurs), we need to do a database-level process full.

Mdx request get the first element of a tuple with datetime

My MDX request gives to me this result:
For my entities, I've multiple years for one value, I need just get the first year for the entity (and others dimensions). I've tried to use the function .FirstChild in the year dimension this return only value with the year '2014' (first year in my dimension). The function .Item() returns only empty values:
SELECT
NON EMPTY
{[Measures].[Value]} ON COLUMNS
,NON EMPTY
{
[EntiteFederal].[EntiteCode].[EntiteCode].ALLMEMBERS*
[T].[Year].[Year].ALLMEMBERS*
[T].[YearDate].[YearDate].ALLMEMBERS
}
DIMENSION PROPERTIES
MEMBER_CAPTION
,MEMBER_UNIQUE_NAME
ON ROWS
FROM [Mycube];
Hopefully this is working - tricky for me to test:
WITH
SET [EntYr] AS
Generate
(
[EntiteFederal].[EntiteCode].[EntiteCode].MEMBERS AS X
,
X.CurrentMember
*
Head
(
NonEmpty
(
[T].[Year].[Year].ALLMEMBERS * [T].[YearDate].[YearDate].ALLMEMBERS
,X.CurrentMember
)
)
)
SELECT
NON EMPTY
[Measures].[Value] ON COLUMNS
,NON EMPTY
[EntYr] ON ROWS
FROM [Mycube];

Filter dimensions for a specific member in MDX

I need to filter the dimension [Line] just for a specific [Year].Member.
For example,
[Time].[2004] to show results ([Product].[Line].[Classic Cars] and [Product].[Line].[Ships]) - excude the rest of [Product].[Line] members for [Time].[2004] but do not exclude [Product].[Line] members for the other [Time].Members.
I need a code compatible with Mondrian.
Any suggestion?
SELECT
NON EMPTY {[Measures].[Sales]} ON COLUMNS,
NON EMPTY NonEmptyCrossJoin([Time].[Years].Members, [Product].[Line].Members) ON ROWS
FROM
[SteelWheelsSales]
Something like this should work:
SELECT
NON EMPTY
{[Measures].[Sales]} ON COLUMNS
,NON EMPTY
{
(
[Time].[2004]
,{
[Product].[Line].[Classic Cars]
,[Product].[Line].[Ships]
}
)
,NonEmptyCrossJoin
(
Except
(
[Time].[Years].MEMBERS
,[Time].[2004]
)
,[Product].[Line].MEMBERS
)
} ON ROWS
FROM [SteelWheelsSales];

MDX - Filter multiple dimensions

I'm trying to form an MDX query such that it returns only the combinations of two dimensions where a measure meets a certain criteria. I thought this would be pretty straight forward using the FILTER function, i.e.
SELECT
NON EMPTY FILTER({[Program].[ByRegion].[Program] * [Performance Metric].[Metric].CHILDREN }, [Measures].[Point Percentage] < .95) ON ROWS,
NON EMPTY ( HIERARCHIZE([Calendar Period].[Y-Q-M].[Month of Quarter].&[3]&[1]&[2009]) , [Measures].[Point Percentage] )ON COLUMNS
FROM [QEP Revenue]
However, after running the query, it is pretty easy to see that I have a mistake because the very first result has a Point Percentage of 1.5172 which is obviously more than .95.
If I completely remove the filter:
SELECT
--NON EMPTY FILTER({[Program].[ByRegion].[Program] * [Performance Metric].[Metric].CHILDREN }, [Measures].[Point Percentage] < .95) ON ROWS,
NON EMPTY ({[Program].[ByRegion].[Program] * [Performance Metric].[Metric].CHILDREN }) ON ROWS,
NON EMPTY ( HIERARCHIZE([Calendar Period].[Y-Q-M].[Month of Quarter].&[3]&[1]&[2009]) , [Measures].[Point Percentage] )ON COLUMNS
FROM [QEP Revenue]
I get a similar result set including values above .95. Am I completely missing the point of a filter, or is there an issue with attempting to filter two dimensions at once?
I don't have your datasource, but this MDX works against the AS2000 sample cube, Foodmart (Sales cube).
SELECT
NON EMPTY
{{[Time].[Quarter].MEMBERS}} ON COLUMNS
,NON EMPTY
Filter
(
CrossJoin
(
{[Customers].[State Province].&[CA]}
,[Promotions].[All Promotions].Children
)
,
(
[Customers].[State Province].&[CA]
,[Time].&[1997].&[Q1]
,[Measures].[Unit Sales]
)
> 300
) ON ROWS
FROM [Sales]
WHERE
[Measures].[Unit Sales];
I got it cracked.
The filter was being applied correctly to the Program and Performance Metric dimensions. The issue was that the filter was applied separately from the Calendar Period dimension. So the Point Percentage of 1.5172 that showed up was allowed to show because there was a Point Percentage in another month that fulfilled the filter requirement.
I was able to rewrite the query as such to get the desired results:
SELECT
NON EMPTY
Filter
(
{
[Program].[ByRegion].[Program]*
[Performance Metric].[Metric].Children*
[Calendar Period].[Y-Q-M].[Month of Quarter].&[3]&[1]&[2009]
}
,
[Measures].[Point Percentage] < 0.95
) ON ROWS
,NON EMPTY
[Measures].[Point Percentage] ON COLUMNS
FROM [QEP Revenue];
Luckily, this query is being used in reporting services, so it is appropriate to move the Calendar Period into the ROWS. However, if I wanted to keep the Calendar Period in the COLUMNS, I wouldn't know how to solve this since the same dimension cannot be used in both axes.