icCube - function calling another function results in NULL - mdx

Below the MDX statement on icCube. (Note that icCube has a non-native language component, called function).
with function article_list() as topcount([Product].[Product].[Article], [amount], 10)
function benchmark_best_index2(i) as sum(order(topcount([Product].[Product].[Article], [amount], 10), [measures].[amount], desc).(i-1) , [measures].[amount])
// why doesnot the following function work?
function benchmark_best_index(list,i) as sum(order(list, [measures].[amount], desc).(i-1), [measures].[amount])
member [measures].[bm_top_amount_doesnotwork] as benchmark_best_index(article_list(),1)
member [measures].[bm_top_amount_doesnotwork_either] as benchmark_best_index( topcount([Product].[Product].[Article], [amount], 10),1)
member [measures].[bm_top_amount_works] as benchmark_best_index2(1)
select { [measures].[amount],[measures].[bm_top_amount_doesnotwork], [measures].[bm_top_amount_doesnotwork_either], [measures].[bm_top_amount_works]} on 0
,article_list() on 1
from sales
I cannot get the calculated measure [bm_top_amount_doesnotwork] and [bm_top_amount_doesnotwork_either] to work.
My idea is to have 2 generic functions, with the 2nd one calling the first one. The end result is a benchmark value that can be used for charts, calculations and so on.
I see this is not possible form the above stated MDX. But is it possible? And if YES, how?

We've to check in detail what went wrong (issue) in the meantime you can force the type of the parameter so the MDX parser knows it is a set :
sum(order( {list} , [measures].[amount], desc).(i-1), [measures].[amount])

Related

MDX linkmember equivalent in DAX

Is there any equivalent of linkmemeber from MDX to DAX?
I am trying to migrate the following script from MDX to DAX
with
member TauxdetransformationQuartileRegion as ([Measures].[Taux_de_transformation_Region],[Bon Envoi].[Bon Envoi].&[True])
member Annees as [Date Creation].[Année].currentmember.name
select {
[Measures].[Tx_Real_Meilleur_Region]
,TauxdetransformationQuartileRegion
} on 0
FROM ( select strtoset(#Region) on 0 from test)
WHERE (
linkmember(strtotuple(#DateFin),[Mois Publication].[Mois de publication])
,{strtotuple(#DateDebut):strtotuple(#DateFin)}
,[Perimetre Ebusiness].[Périmètre E-Business].&[O]
,{[MER_Publication].[Detail Type Visiteur].&[Prospect],[MER_Publication].[Detail Type Visiteur].&[Client direct]}
,( - { [Origine_Marketing].[Entree Parcours].&[SiteAgent] } )
)
MDX query parameters are typically strings with member unique names ("[Dim].[Attr].&[Key]") which you must convert to a member with StrToMember(#Param). And if you need to switch hierarchies you the use LinkMember.
DAX parameters are just the values. So the parameter will work against any dimension. Thus LinkMember isn’t needed.
Here is an article about DAX parameters. For Date type parameters I forget if you just say 'Date'[Date] = #DateParam or if you have to say 'Date'[Date] = DATEVALUE(#DateParam). My recollection is that it depends on whether the parameter is Date type (use the first approach) or String type (use the DATEVALUE approach).

MDX currentMember get me error

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).

Mondrian MDX error with CDate and DateDiff usage

How could be solved problem below?
ERR: mondrian.olap.fun.MondrianEvaluationException: mondrian.olap.InvalidArgumentException: Mondrian Error:Invalid parameter. expression parameter of CDate function must be formatted correctly
My MDX request:
WITH
MEMBER
[Measures].[diff] as 'datediff("d",CDate([TimeDim.TimeHir].CurrentMember.Name),now())'
....
Have you tried other member properties:
WITH
MEMBER [Measures].[diff] as
'datediff("d",CDate([TimeDim.TimeHir].CurrentMember.MEMBER_VALUE),now())'
or
WITH
MEMBER [Measures].[diff] as
'datediff("d",CDate([TimeDim.TimeHir].CurrentMember.MEMBER_key),now())'
or
WITH
MEMBER [Measures].[diff] as
'datediff("d",CDate([TimeDim.TimeHir].CURRENTMEMBER.Properties('Key0', Typed)),now())'
Edit
This one works for me against AdvWks :
WITH
MEMBER [Measures].[Date_MEMBER_VALUE] as
[Date].[Calendar].CurrentMember.MEMBER_VALUE
MEMBER [Measures].[Diff_MEMBER_VALUE] as
datediff("D",CDate([Measures].[Date_MEMBER_VALUE]),now())
SELECT
{
[Measures].[Date_MEMBER_VALUE]
,[Measures].[Diff_MEMBER_VALUE]
}
ON 0,
tail([Date].[Calendar].[Date],12) ON 1
FROM [Adventure Works];
Edit
From here it looks like .MEMBER_VALUE does not exist in Mondrian so try using the above code with just .VALUE instead: http://mondrian.pentaho.com/documentation/mdx.php
You can use DateSerial function to convert your value to datetime format which is accepted by CDate

MDX CurrentMember with SSAS 2008 doesn't work as stated by MSDN

First of all I use the SQL Management Studio for this query (no Excel 2007 that seems to have problems):
WITH
SET [Project period dates] AS
{
StrToMember("[Time].[Date].&[" + [Project].[ParentProject].CURRENTMEMBER.PROPERTIES("Project Start Iso") + "]"):
StrToMember("[Time].[Date].&[" + [Project].[ParentProject].CURRENTMEMBER.PROPERTIES("Project End Iso") + "]")
}
MEMBER [Measures].[Test] AS ([Project period dates].COUNT)
SELECT
{
[Measures].[Test]
}
on 0,
NONEMPTY ([Project].[ParentProject].MEMBERS)
DIMENSION PROPERTIES [Project].[ParentProject].[Project Duration], [Project].[ParentProject].[Project Start Iso], [Project].[ParentProject].[Project End Iso]
on 1
FROM
[MyCube]
WHERE
(
[Orgunit].[Orgunit].&[448]
)
This query delivers a list of projects with its three properties and a calculated member that is based upon my calculated set. The properties show the right values, but the calculated member shows always the same: the result of the very first project it should be calculated for.
I don't really understand why, because MSDN says:
The current member changes on a hierarchy used on an axis in a query.
Therefore, the current member on other hierarchies on the same
dimension that are not used on an axis can also change; this behavior
is called 'auto-exists'.
They give examples with calculated members, but I think that should also work with calculated sets, I have read that query-based calculated sets are dynamic by nature. Maybe somebody can tell me if I understood that wrong or what else is my problem here.
The named set are only computed once within a query. That is why your calculated member always return the same value.
You just have to remove the named set from your query:
MEMBER [Measures].[Test] AS {
StrToMember("[Time].[Date].&[" + [Project].[ParentProject].CURRENTMEMBER.PROPERTIES("Project Start Iso") + "]"):
StrToMember("[Time].[Date].&[" + [Project].[ParentProject].CURRENTMEMBER.PROPERTIES("Project End Iso") + "]")
}.COUNT

Issue in displaying Decimal fields in SSRS with mdx Query

We are facing issue while displying the amount in ssrs reports which makes use of mdx query.
For Example : this value is retured by mdx query 278.25 but when it is binded with ssrs it shows 27.825,00.
We are using culture de-DE(German) in report.
We have tried the following solutions but still the issue remains in SSRS report:
From mdx side We have tried FORMAT_STRING = "#0,00" function for displying numeric value.
From report side we have tried to use replace function to replace '.' with ',', but its not working fine.
Sample Query can be found below
WITH
MEMBER [Measures].[CumEGTKDAmount] AS sum({[Time].[Month].FIRSTCHILD: [Time].[Month].CurrentMember},[Measures].[EGTKD] * [Measures].[AvgStockPrice])
SELECT
{
[Measures].[CumEGTKDAmount]
} ON COLUMNS,
NON EMPTY {
topcount(
(
STRTOSET("[Dim Item].[ItemHierarchy].[Item No].&[00001133]")
)
,50,[Measures].[ReklaQuote])
} ON ROWS
FROM [QM]
Thanks
Try this:
=Replace(Format(Fields!YourFieldName.Value, "#,###0.00"),",",".")