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 )
)
)
Related
I'd like to store a table in a variable, but based on conditions of the visual.
e.g.
VAR ColumnValues = values( SpecificTable[SpecificColumn] )
works fine, but what I'd like to do is:
VAR ColumnValues = if([some condition T/F], values( SpecificTable1[SpecificColumn1] ) , SpecificTable2[SpecificColumn2] )
For reference, this question is in exploration of workarounds to solve question: Dynamic measure that responds to dynamic dimension which I marked as answered prematurely. I still do not have a solution to dynamically work with column values in DAX.
I've not been able to work out a syntax that allows this. Switch only returns scalar strings, and IF seems to only allow for a scalar result, not a table. Any other options I'm not thinking of?
Was not explicitly using any condition, but the condition that I was checking for, that I was able to get the desired result with the following:
Create Field Parameter (name it "_Dimension"), selecting the columns that need to be in play in the DAX
DAX looks like this:
VAR SelectedDim = SELECTEDVALUE( _Dimension[_Dimension Fields] ) //fully qualified - created by field parameter
//stage the values in each of the columns available
VAR Dim1Values = ADDCOLUMNS( VALUES( Dim1[Column1] ) , "RowValue" , Dim1[Column1] , "ColumnName" , "'Dim1'[Column1]" )
VAR Dim2Values = ADDCOLUMNS( VALUES( Dim1[Column2] ) , "RowValue" , Dim1[Column2] , "ColumnName" , "'Dim1'[Column2]" )
//... same pattern, as many column as needed
VAR SelectedDimValues = FILTER( UNION( Dim1Values, Dim2Values ) , [RowValue] = SelectedDim ) //return the values just for the selected column
SelectedDimValues is a Variable that contains a table with the rows from my selected dimension.
I have a complex SQL query where I have a few cases that use END AS variableName. I then use variableName to do some logic and then create a new variable which I want in the output result. However when I run the query, all the END AS variableNames that I have used are also outputted in the results.
Is there a way that I can exclude these variables as I only want the final variable that uses these variableNames.
Thanks
EDIT, here is a query explaining my problem
SELECT DISTINCT
mt.src_id AS “SRC_ID”,
CASE
WHEN mt.cd = ‘TAN’ THEN
(
(
SELECT SUM(src_amt)
FROM source_table st
WHERE mt.id = st.id
AND st._cd = ‘TAN’
AND st.amt_cd = ‘ABL’)
)
END AS src_amt
FROM MAIN_TABLE mt
WHERE
mf.dt >= 2021-12-12
AND SRC_AMT > 10
I need SRC_AMT to be used as some sort of logic but when I run the query, it prints out in the output as it's own column. I want to ignore this variable
you can wrap the whole thing into a new select-statement:
select SRC_ID from ( <entire previous query here> )
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.
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] )
)
How can you use a LET temporary variable inside the Where clause in an OrientDB SQL subQuery.
Here is the context in wich I'm trying to use it.
select *, $t.d from Currency
let $t = (select createdDate.asLong() as d from 13:1)
where createdDate.asLong() >= $t.d and #rid <> #13:1
order by createdDate ASC
The validation in the where statement for the dates does not work. The subQuery actually works on its own. The Query works as well when replacing $t.d with the result from the subQuery.
The $t.d is an array so you are comparing something like createdDate.asLong() >= [1234599]
You have to do this: createdDate.asLong() >= $t[0].d