I want to filter a set by another set, which is returned by the event #{date}.
The following code only works if the #{date} event returns a single member (e.g. [TIME_DIMENSION].[YEAR].[2010]). Any suggestions how to filter if the event returns more than one member?
WITH SET [A] AS
Filter(
TopPercent(
[PRODUCTS].members - [PRODUCTS].[all],
80,
[Measures].[Sales]
),
#{date}
)
Maybe you could use the NonEmpty function? It would return the set of non empty tuples from the set.
WITH SET [A] AS
NonEmpty(
TopPercent(
[PRODUCTS].members - [PRODUCTS].[all],
80,
[Measures].[Sales]
)
,#{date} * [Measures].[Sales]
)
Related
I have a set lets just say:
set [A] as {
([Measures].[X],[somedimension].[A])
[Measures].[Y],[somedimension].[A])
[Measures].[Z],[somedimension].[A])
}
What I need to do is I have to divide this set with a specific value say: [Measures].[P]
Is it possible to do something like this in MDX? If yes then how. Because if I use a normal divide operation it fives an error saying "The Divide function expects a string or numeric expression for the 1 argument. A tuple set expression was used"
SET usually is just a list of items from a dimension. Use FILTER with needed condition to get items which will satisfy it.
WITH
SET [A] AS {Your Set Members}
SET [A WITH P Over 100] AS FILTER([A], [Measures].[P] > 100)
SET [All Others] AS [A] - [A WITH P Over 100] -- Just for example
SELECT { [P] } ON COLUMNS,
{[A WITH P Over 100]} ON ROWS
FROM [Your Cube]
WHERE ([P] < 1000)
In MDX, is it possible create a Named Sets when including with the Measures Axis eg
WITH
SET [MyFields] AS (
IIF((IsEmpty([Measures].[MeasureField])), null,
IIF(([School].[Key].CurrentMember IS [School].[Key].&[9999] or [School].[Key].CurrentMember IS [School].[Key].&[8888])
,{[Measures].[MeasureField]}
,IIF(([Semester].[Key].CurrentMember IS [Semester].[Key].&[1])
,{[Measures].[MeasureField]}
,null
)
)
)
)
SET [MyNonEmpty] AS (
NonEmpty(
{([Student].[UniqueId].[UniqueId].members,({ [School].[Key].&[9999], [School].[Key].&[8888] })
)
)
SELECT {
MyFields
} ON COLUMNS
,NON EMPTY { (
MyNonEmpty
* [Dim1].[Field1].[Field1].ALLMEMBERS
* [Dim2].[Field2].[Field2].ALLMEMBERS
...
}
...
Although I can use a Calculated Member on the Dimensions (COLUMNS above) axis (and successfully return rows), the above syntax which uses the Named SET in the Measures (ROWS) axis, returns no rows (and no error).
Just a note - in the the above example no rows are returned regardless of whether MyFields is empty or non-empty
I want to search date between two columns of same dimension. Columns name is start date and end date. I tried every thing, following query give me this error : Mondrian Error:Internal error: Cannot deduce type of call to function ':'
MDX query :
WITH
SET [~ROWS] AS
Hierarchize
(
{
{[Location_Cluster.default].[All Location_Cluster.defaults]}
,{[Location_Cluster.default].[Location_Cluster].MEMBERS}
}
)
MEMBER [Measures].[QTY Percent] AS
[Measures].[Total_Quantity]
/
(
[Measures].[Total_Quantity]
,[Location_Cluster.default].[All Location_Cluster.defaults]
)
,format_string = '0.00%'
MEMBER [Measures].[Revenue Percent] AS
[Measures].[Total_Revenue]
/
(
[Measures].[Total_Revenue]
,[Location_Cluster.default].[All Location_Cluster.defaults]
)
,format_string = '0.00%'
MEMBER [Measures].[Margin Percent] AS
[Measures].[Total_Margin]
/
(
[Measures].[Total_Margin]
,[Location_Cluster.default].[All Location_Cluster.defaults]
)
,format_string = '0.00%'
SELECT
NON EMPTY
{
[Measures].[Sku_Count]
,[Measures].[Total_Quantity]
,[Measures].[QTY Percent]
,[Measures].[Total_Revenue]
,[Measures].[Revenue Percent]
,[Measures].[Total_Margin]
,[Measures].[Margin Percent]
} ON COLUMNS
,NON EMPTY
[~ROWS] ON ROWS
FROM [APCS_SALES_CUBE]
WHERE
(
{[Date].[Start_Date].&[2017-01-01] : NULL}
,{NULL : [Date].[End_Date].&[2017-03-01]}
,[Cluster.Cluster_Id].[2]
,[Taxonomy.default].[Taxonomy_ID].[3]
,[Company.Company_Name].[Compnay_Name].[1]
);
I followed following links to resolve this issue. But don't know how to apply specify function in Mondrian MDX
https://ask.sqlservercentral.com/questions/95478/mdx-for-records-between-date-range-where-start-and.html#answer-142811
https://www.purplefrogsystems.com/blog/2013/04/mdx-between-start-date-and-end-date/#comment-1981
Your query is not well formed. You need to make set out of the range you want to slice. Here is an example:
WITH SET [~ROWS] AS
(${dateFromParameter} : ${dateToParameter})
MEMBER Measures.[number] as
FORMAT([date].[godina].CurrentMember.PROPERTIES("datum"), "dd.mm.yyyy")
SET [ROOT] AS
FILTER([ORG].[org_id].Members, [ORG].[org_id].currentmember.parent.parent=[ORG].[org_id].currentmember.parent)
SELECT
NON EMPTY {[Measures].[total], Measures.[number]} ON COLUMNS,
NON EMPTY [ROOT] * [~ROWS] ON ROWS
FROM [svcs]
This MDX function raise error :
with member measures.x as
(
[Date].[Date].[Date].&[20160101] : [Date].[Date].[Date].currentmember.value
,
[Measures].[current balance]
)
select measures.x on columns,
[Branch].[HeadOffice Branch].[Head Office Code] on rows
from MyCube
Error is :
The CURRENTMEMBER function expects a hierarchy expression for the 1 argument. A member expression was used.
But when I use
[Date].[Date].[Date].&[20160101] : [Date].[Date].[Date].&[20160131]
It works good
why?
This is valid mdx:
[Date].[Date].[Date].&[20160101] : [Date].[Date].currentmember
Although this is not:
WITH member measures.x AS
(
[Date].[Date].[Date].&[20160101] : [Date].[Date].currentmember
,
[Measures].[current balance]
)
It is not valid because round braces (...) signify a tuple but a tuple requires exact co-ordinates so the first argument cannot be a set.
You could add an aggregation such as SUM:
WITH member measures.x AS
SUM
(
[Date].[Date].[Date].&[20160101] : [Date].[Date].currentmember
,
[Measures].[current balance]
)
This is valid mdx but if you do not have [Date].[Date] in context i.e. in the WHERE or SELECT clause then all it is returning is the All member.
Why are you using [Date].[Date].currentmember ?
CURRENTMEMBER works on an attribute hierarchy (in your case [Date].[Date]). So [Date].[Date].CURRENTMEMBER will work.
Also you will need to take out the value selector, as your expression returns a set of dates (member : member returns a set of all the members between those two members).
My MDX-Query looks like this:
WITH
MEMBER [YEAR].[A2014_1-12] AS
([YEAR].[2014], [TYPE].[ACTUAL]),
MEMBER [YEAR].[P2014_1-12] AS
([YEAR].[2014], [TYPE].[PLAN]),
MEMBER [YEAR].[P2015_1-12] AS
([YEAR].[2015], [TYPE].[PLAN]),
MEMBER [YEAR].[A2015_YTD] AS
SUM(
{[YEARPERIOD].[201501]:[YEARPERIOD].[201509]}
,(
[Measures].currentmember
,[TYPE].[ACTUAL]
)
)
SELECT
{
[YEAR].[A2014_1-12],
[YEAR].[P2014_1-12],
[YEAR].[P2015_1-12],
[YEAR].[A2015_YTD]
}
ON COLUMNS,
NON EMPTY
[COST_CENTER]
*[COST_ELEMENT] ON ROWS
FROM [CUBE]
WHERE ([Measures].[COSTS]);
The Query itself is working. However it is also returning a lot of zero-rows and I would like to get rid of these zero-rows. The strange thing is - If I put only one MEMBER (e.g. [YEAR].[A2014_1-12]) on the COLUMNS-axis it is not returning any zero-rows. But as soon as I start to add another MEMBER to the COLUMN-axis it is also many returning zero-rows (It seems like it is ignoring the NON EMPTY in my CROSSJOIN). How can I remove the zero-rows in the above MDX-Query?
Try this as a start
WITH
MEMBER [YEAR].[A2014_1-12] AS
iif(
([YEAR].[2014], [TYPE].[ACTUAL]) = 0
,null
,([YEAR].[2014], [TYPE].[ACTUAL])
)
MEMBER [YEAR].[P2014_1-12] AS
iif(
([YEAR].[2014], [TYPE].[PLAN]) = 0
,null
,([YEAR].[2014], [TYPE].[PLAN])
)
SELECT
NON EMPTY
{
[YEAR].[A2014_1-12],
[YEAR].[P2014_1-12]
}
ON COLUMNS,
NON EMPTY
[COST_CENTER]
*[COST_ELEMENT] ON ROWS
FROM [CUBE]
WHERE ([Measures].[COSTS]);
As an aside you do not need to define the current member of the measures hierarchy in this definition:
MEMBER [YEAR].[A2015_YTD] AS
SUM(
{[YEARPERIOD].[201501]:[YEARPERIOD].[201509]}
,(
[Measures].currentmember
,[TYPE].[ACTUAL]
)
)
This is enough:
MEMBER [YEAR].[A2015_YTD] AS
SUM(
{[YEARPERIOD].[201501]:[YEARPERIOD].[201509]}
,([TYPE].[ACTUAL])
)
Try this instead:
WITH
MEMBER [YEAR].[A2014_1-12] AS
iif(
([YEAR].[2014], [TYPE].[ACTUAL]) = 0
,null
,([YEAR].[2014], [TYPE].[ACTUAL])
)
MEMBER [YEAR].[P2014_1-12] AS
iif(
([YEAR].[2014], [TYPE].[PLAN]) = 0
,null
,([YEAR].[2014], [TYPE].[PLAN])
)
SET [X] AS
NonEmtpy(
[COST_CENTER]*[COST_ELEMENT],
{[YEAR].[A2014_1-12],[YEAR].[P2014_1-12]}
)
SELECT
NON EMPTY
{
[YEAR].[A2014_1-12],
[YEAR].[P2014_1-12]
}
ON 0,
//NON EMPTY
[X] ON 1
FROM [CUBE]
WHERE ([Measures].[COSTS]);