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).
Related
I am using copy activity in ADF in which i have following pseudo query:
SELECT
{
[Measures].[**************],
[Measures].[**************],
[Measures].[**************]
} ON COLUMNS,
NON EMPTY
{
[0CALWEEK].[LEVEL01].MEMBERS
}
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM cubeName/ReportName
SAP VARIABLES [SAP_VARIABLE_NAME]
INCLUDING [0CALWEEK].[201905]
In the above i want to replace '201905' dynamically,there is no current function availabe to get WeekOfYear in ADF Expressions and functions OR can i use MDX Query to generate WeekOfYear
Take a look at this example how it changes value for a member value. Please note I have answerd if from phone so some syntax issue might exist.
With member measures.t
As
Case when
[0CALWEEK].[LEVEL01]. currentmember.name="'201905"
Then 1
Else
0
End
SELECT
{
[Measures].[t]
} ON COLUMNS,
NON EMPTY
{
[0CALWEEK].[LEVEL01].MEMBERS
} ON ROWS
FROM cubeName/ReportName
What is the difference between representing tuple in an mdx query as
[CF Type].[CF TYPE].&[6]
OR
[ValScen].[Scenario Type].&[Term Point Rates]
Can I use the &[number] and the &[actual string] format interchangeably? If the cube is generated by another system, can the &[6] be different for each generation in usual practice? Or is it safer to use StrToMember or StrToSet. But this is not efficient as per this article. To give some context, in my case I use it like in below pseudocode
SELECT NON EMPTY { [Measures].x} ON COLUMNS, NON EMPTY { (My Column1 * My Column2)} DIMENSION PROPERTIES MEMBER_CAPTION ON ROWS FROM ( SELECT ( { [CF Type].[CF TYPE].&[6] } ) ON COLUMNS FROM
( SELECT ( { [ValScen].[Scenario Type].&[Term Point Rates] } ) ON COLUMNS FROM [My Cube]]))
WHERE ( [ValScen].[Scenario Type].&[Term Point Rates], [CF Type].[CF TYPE].&[6] )
Those are members and not tuples. A Tuple would be surrounded by braces ().
I think they are interchangeable syntax if you’re using the caption such as .&[hello] and .[hello] but if you use the key then the ampersand is mandatory.
I have one Date column in my fact table, and due to some client api requirement I need to format this column as string while grouping data using SUMMARIZE function. Below is the sample query, which I am using:
EVALUATE(
CALCULATETABLE(
ADDCOLUMNS(
SUMMARIZE(
'BreakTable',
'BreakTable'[Column1],
'BreakTable'[Column2],
'BreakTable'[DateColumn1], --This needs to be formatted
),
"BreakCount",FORMAT('BreakTable'[BreakCount],"#,##0")
)
))
I have tried using FORMAT function in SUMMARIZE, and that does not work by default. I can not add new column to FactTable, so need to solve this while querying itself.
Is there any other way to achieve this? Any help is appreciated.
As per suggestion, adding more information.
We are using Sql Server 2014.
You could use the SELECTCOLUMNS() function. This function works similarly to the ADDCOLUMNS() function, except that it only returns the columns you specify.
Here is an example of how you can alter your existing query:
EVALUATE(
SELECTCOLUMNS(
SUMMARIZE(
'BreakTable',
'BreakTable'[Column1],
'BreakTable'[Column2],
'BreakTable'[DateColumn1],
),
"Column1", [Column1],
"Column2", [Column2],
"DateColumn1", FORMAT([DateColumn1],"YourFormatHere"), --Format your DateColumn here
"BreakCount",FORMAT('BreakTable'[BreakCount],"#,##0")
)
)
EDIT:
Please note that the SELECTCOLUMNS() function is only available from SQL Server 2016 and up.
I'm working on a Tabular cube in Visual Studio.
I have a DAX formula in the cube that works fine:
SUMX(FILTER(factFHA, factFHA[EventCd]="D"), [LoanCount])
When I run it in SSMS as:
evaluate(
SUMX(FILTER(factFHA, factFHA[EventCd]="D"), [LoanCount])
)
it fails with following error:
Query (1, 1) The expression specified in the EVALUATE statement is not a valid table expression.
I have 2 other formulas that both work fine:
evaluate(factFHA)
evaluate(filter('factFHA', [EventCd] = "D"))
I can't figure out what is wrong with the SUMX with FILTER
Please advise. Thank you.
EVALUATE function only works if you pass a table or an expression that returns a table, you are passing a SUMX function which return a scalar value (Decimal).
The syntax to write queries using DAX, is as follows:
[DEFINE { MEASURE <tableName>[<name>] = <expression> } -> Define a session (optional) measure
EVALUATE <table> --> Generate a table using your measures or creating calculated columns
[ORDER BY {<expression> [{ASC | DESC}]}[, …] --> Order the returned table by a passed column or expression
[START AT {<value>|<parameter>} [, …]]] --> This is an ORDER BY Sub-clause to define from which the query results will start.
Define your measure then use then use it inside the EVALUATE clause using a expression that evaluates to a table.
DEFINE
MEASURE factFHA[MyMeasure] =
SUMX ( FILTER ( factFHA, factFHA[EventCd] = "D" ), [LoanCount] )
EVALUATE
( SUMMARIZE ( FILTER ( factFHA, factFHA[EventCd] = "D" ), factFHA[AnyColumnToGroup]
, "Sum of MyMeasure", SUM ( factFHA[MyMeasure] ) ) )
Let me know if this helps.
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