The expression specified in the EVALUATE statement is not a valid table expression - ssas

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.

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

Using condition in Calculatetable ()

I've a problem on Table filtering while using CALCULATETABLE()
I tried to use the script with condition for CALCULATETABLE():
XeroInvoices[AmountPaid] < XeroInvoices[AmountDue]
EVALUATE
SUMMARIZE(
CALCULATETABLE(XeroInvoices,
XeroInvoices[Status] = "AUTHORISED",
XeroInvoices[DueDate] <= TODAY(),
XeroInvoices[AmountPaid] < XeroInvoices[AmountDue]
),
XeroInvoices[Number],
XeroInvoices[Reference],
XeroInvoices[Status],
XeroInvoices[Date],
XeroInvoices[DueDate],
XeroInvoices[AmountPaid],
XeroInvoices[AmountDue]
)
but the error that i get in DAX Studio is as following:
Query (6, 30) The expression contains multiple columns, but only a single column can be used in a True/False expression that is used as a table filter expression.
I managed only to kinda achieve that I wanted only like this -- crating new column within SUMMARIZE() syntax and later filtering it in Excel:
EVALUATE
SUMMARIZE(
CALCULATETABLE(XeroInvoices,
XeroInvoices[Status] = "AUTHORISED",
XeroInvoices[DueDate] <= TODAY()
),
XeroInvoices[Number],
XeroInvoices[Reference],
XeroInvoices[Status],
XeroInvoices[Date],
XeroInvoices[DueDate],
XeroInvoices[AmountPaid],
XeroInvoices[AmountDue],
"AmPaid<AmDue",XeroInvoices[AmountPaid]< XeroInvoices[AmountDue]
)
Does anyone know what might be the reason for this Err in CALCULATETABLE() and what might be a proposed solution?
Thanks!!
Check this
To filter by multiple columns you have to explicitly specify the "FILTER"
CALCULATETABLE (
Product,
FILTER (
Product,
OR ( Product[Color] = "Red", Product[Weight] > 1000 )
)
)

IF Statement in a calculated field (SSAS Tabular)

I'm in the process of creating a tabular model cube in SSAS and I've become a bit stuck on some of my measures for the calculated columns
I have already converted this case statement to an IF in SSAS
case when PROPERTY_CHARGE.PCH_CURRENT_IND='Y' then PROPERTY_CHARGE.PCH_AMT else 0 end
is now
=If ([PCH_CURRENT_IND]="Y", [PCH_AMT],0)
I'm now struggling to convert this one:
sum(case when PROPERTY_CHARGE.PCH_CURRENT_IND='N' and PROPERTY_CHARGE.PCH_END_DATE is null then PROPERTY_CHARGE.PCH_AMT else 0 end
I've tried various arrangements but no matter what i'm getting errors either related to is null or AND not being available in this context or other errors advising I have too many arguments.
Can anyone assist please?
IN tabular is very different the logic, you can create a measure like this :
MeasureName:=CALCULATE(sum([PCH_AMT]),FILTER(PROPERTY_CHARGE,[PCH_CURRENT_IND]="N"&&[PCH_END_DATE]=BLANK()))
ANd give you the same result of case
use:
=If ([PCH_CURRENT_IND]="Y", [PCH_AMT],BLANK())
and then :
MeasureName:
=CALCULATE(sum([PCH_AMT]),FILTER(PROPERTY_CHARGE,[PCH_CURRENT_IND]="N"&&[PCH_END_DATE]=BLANK()))
that is the same as the case
This solution will be a little more performant than the previous posts and a little easier to read, use this for a Measure:
Strruggling To Convert measure:=
CALCULATE (
SUM ( 'PROPERTY_CHARGE'[PCH_AMT] ),
FILTER (
ALL ( 'PROPERTY_CHARGE'[PCH_CURRENT_IND], 'PROPERTY_CHARGE'[PCH_END_DATE] ),
AND (
'PROPERTY_CHARGE'[PCH_CURRENT_IND] = "N",
ISBLANK ( 'PROPERTY_CHARGE'[PCH_END_DATE] )
)
)
)
Struggling To Convert Calculate column :=
SWITCH (
TRUE (),
AND (
'PROPERTY_CHARGE'[PCH_CURRENT_IND] = "N",
ISBLANK ( 'PROPERTY_CHARGE'[PCH_END_DATE] )
), SUM ( 'PROPERTY_CHARGE'[PCH_AMT] )
)

Parameterizing Asymmetric Set in MDX?

I upgraded to SQL server 2008 R2 from 2005, and now this query is no longer working(although I don't rule out something I did being the cause). I have simplified the names/query to demonstrate the issue:
SELECT
NON EMPTY
{
[BizDim].[County].[County]
* [BizDim].[name].[name]
}
ON COLUMNS,
{
[Biz Line Type Dimension].[Line Number].[Line Number]
* [Biz Line Type Dimension].[Display Name].[Display Name]
}
ON ROWS
FROM [TPS Data View]
Where (
STRTOSET("{[BizDim].[County ID].&[16]}", CONSTRAINED)
,STRTOSET("{([BizDim].[Corp].[Corp].ALLMEMBERS,[BizDim].[Local].[Local].ALLMEMBERS,[BizDim].[HQ].[HQ].&[x]),([BizDim].[Corp].[Corp].&[x],[BizDim].[Local].[Local].ALLMEMBERS,[BizDim].[HQ].[HQ].ALLMEMBERS)}")
)
Essentially this is a logical OR saying if column Corp == 'x' OR HQ == 'x' then include it in the result. This is known as an assymmetric(sic) set.
The above gives the error:
The Tuple function expects a tuple expression for the 3 argument. A tuple set expression was used.
I can remove the STRTOSET function and it works perfectly:
Where (
STRTOSET("{[BizDim].[County ID].&[16]}", CONSTRAINED)
,{([BizDim].[Corp].[Corp].ALLMEMBERS,[BizDim].[Local].[Local].ALLMEMBERS,[BizDim].[HQ].[HQ].&[x]),([BizDim].[Corp].[Corp].&[x],[BizDim].[Local].[Local].ALLMEMBERS,[BizDim].[HQ].[HQ].ALLMEMBERS)}
)
However, this is no good because the actual query is parameterized, so it must work with a STRTO* function:
Where (
STRTOSET(#Counties, CONSTRAINED)
,STRTOSET(#BizTypes)
)
I have tried STRTOTUPLE and get the same error.
I could build the query dynamically but I'd rather avoid taking that risk, especially given that it worked fine before with a parameter.
So the question is, how to get this assymmetric set to work as a parameter again in SQL Server 2008 R2 SSAS?
Update:
Note that this eliminates the error by replacing the keys will ALLMEMBERS, but doesn't actually filter anything so it is useful only to show in general my syntax doesn't seem to be bad:
Where (
STRTOSET("{[BizDim].[County ID].&[16]}", CONSTRAINED)
,{([BizDim].[Corp].[Corp].ALLMEMBERS,[BizDim].[Local].[Local].ALLMEMBERS,[BizDim].[HQ].[HQ].ALLMEMBERS),([BizDim].[Corp].[Corp].ALLMEMBERS,[BizDim].[Local].[Local].ALLMEMBERS,[BizDim].[HQ].[HQ].ALLMEMBERS)}
)
I did manage to get this working in a less dynamic way, but quite annoying. Basically my filter would need to be divided into many different parameters because I would need a STRTOSET call for each one:
Where (
STRTOSET("{[BizDim].[County ID].&[16]}", CONSTRAINED)
,{
STRTOSET("([BizDim].[Corp].[Corp].ALLMEMBERS,[BizDim].[Local].[Local].ALLMEMBERS,[BizDim].[HQ].[HQ].&[x])")
,STRTOSET"([BizDim].[Corp].[Corp].&[x],[BizDim].[Local].[Local].ALLMEMBERS,[BizDim].[HQ].[HQ].ALLMEMBERS)")
}
)
[edited after comments]
Where
STRTOSET("{[BizDim].[County ID].&[16]}", CONSTRAINED)
* STRTOSET("{([BizDim].[Corp].[Corp].ALLMEMBERS,[BizDim].[Local].[Local].ALLMEMBERS,[BizDim].[HQ].[HQ].&[x]),([BizDim].[Corp].[Corp].&[x],[BizDim].[Local].[Local].ALLMEMBERS,[BizDim].[HQ].[HQ].ALLMEMBERS)}")
They might be an ambiguity with the ( x, y, z ) notation which is either a tuple or a parenthesis operator; e.g., ( {}, {} ) is a crossjoin.
Perhaps you need an explicit wrapping into a set :
{ [BizDim].[HQ].[HQ].&[x] }
Or replace:
([BizDim].[Corp].[Corp].ALLMEMBERS,[BizDim].[Local].[Local].ALLMEMBERS,[BizDim].[HQ].[HQ].&[x])
with an explicit crossjoin:
{ [BizDim].[Corp].[Corp].ALLMEMBERS * [BizDim].[Local].[Local].ALLMEMBERS * { [BizDim].[HQ].[HQ].&[x] } }
Hope that helps.

MDX multiple EXCEPT filter in calculated member

I have following query for calculated member:
SUM(
EXCEPT([Policy].[Policy Status].[Policy Status],[Policy].[Policy Status].&[Void])
, [Measures].[CountPolicyEndorsesNull]
)
What I want is to include another EXCLUDE filter. I have tried following:
SUM(
{EXCEPT([Policy].[Policy Status].[Policy Status],[Policy].[Policy Status].&[Void])}
*
{EXCEPT([Invoice].[Invoice Status].[Invoice Status],[Invoice].[Invoice Status].&[Void])}
, [Measures].[CountPolicyEndorsesNull]
)
but it returns more result than the first query. Any ideas?
Your syntax is correct. The reasons it could be more are the following:
You have negative results in ([Invoice].[Invoice Status].&[Void], [Measures].[CountPolicyEndorsesNull])
You have a default member set on [Invoice].[Invoice Status].[Invoice Status].
Try returning the following query:
select
[Measures].[CountPolicyEndorsesNull]
on columns,
{[Invoice].[Invoice Status].DefaultMember,
[Invoice].[Invoice Status].&[Void]
}
on rows
from [CubeName]
That will get you your culprit.