Forum Discussion
SELECTEDVALUE inside table constructor
Hi,
I have the following measure inside a filter context where the only selected value for column 'ParameterTable'[ItmNam] is "A" (in fact it's a parameter table):
CALCULATE(
COUNTROWS('Table'),
'Table'[ItemName] IN {SELECTEDVALUE('ParameterTable'[ItmNam])}
)
But the measure is not counting the rows in table 'Table' where ItemName = "A".
If I change the measure as follows, it works fine:
CALCULATE(
COUNTROWS('Table'),
'Table'[ItemName] IN {"A"}
)
Why SELECTEDVALUE doesn't works inside a table constreuctor?
Where is this limitation written or explained?
Note: I don't need a workaround (variables can solve it), I need the conseptual explanation or documentation plese.
Thank you!
Alex_Sawdo, ALLSELECTED isn't necessarily what you want (though it might be in some cases).
I'd suggest one of the following instead:
CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[ItemName] IN VALUES ( 'ParameterTable'[ItmNam] ) )CALCULATE ( COUNTROWS ( 'Table' ), TREATAS ( VALUES ( 'ParameterTable'[ItmNam] ), 'Table'[ItemName] ) )This doesn't really answer OP's question though.
juan_pablo, in my testing, the first measure does do what you're expecting if a single parameter value is selected.
5 Replies
- Alex_SawdoResolver II
If I recall correctly, SELECTEDVALUE() only will ever return a single value, and cannot return multiple values at once. What you should do is this:
CALCULATE( COUNTROWS( 'Table' ), 'Table'[Column1] IN ALLSELECTED(ParamTable[Column1]) )This will properly count all of the selected values from the Param table, hence ALLSELECTED() rather than SELECTEDVALUE().
- AlexisOlsonSuper User
Alex_Sawdo, ALLSELECTED isn't necessarily what you want (though it might be in some cases).
I'd suggest one of the following instead:
CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[ItemName] IN VALUES ( 'ParameterTable'[ItmNam] ) )CALCULATE ( COUNTROWS ( 'Table' ), TREATAS ( VALUES ( 'ParameterTable'[ItmNam] ), 'Table'[ItemName] ) )This doesn't really answer OP's question though.
juan_pablo, in my testing, the first measure does do what you're expecting if a single parameter value is selected.- juan_pabloHelper V
Hi AlexisOlson, thank you very much. It seems I oversimplified the example. There was a KEEPFILTERS involved. Attached is the original model, where you can see how differently these two measures behave:
Filter Table = CALCULATE( COUNTROWS('Item'), KEEPFILTERS('Category'[ItmsGrpNam] IN {SELECTEDVALUE('Categoria Obj 1'[ItmsGrpNam])}) ) vs Filter Table OK = CALCULATE( COUNTROWS('Item'), KEEPFILTERS('Category'[ItmsGrpNam] IN {"Viaka"}) )Why do they behave differently?