Forum Discussion
Topn function using a Parameter
- Anonymous5 years ago
// Careful here: this returns a table // so it can't be a measure!!! Measures // never return tables, only scalar // values. [5 mejores productos] = var vProdCount = SELECTEDVALUE( 'Top N'[Top N] ) var vResult = TOPN( vProdCount, ADDCOLUMNS( DimProducto[EnglishProductName], "@Suma", CALCULATE( FactVentas[Ventas] ) ), [@Suma] ) RETURN vResultYou can try the above... but this is not a measure. The code returns a table (as does yours), so I'm not sure what you're trying to achieve with this. If no selection has been made in the Top N table, then this will return nothing. And for such a selection to occur, the parameter table must be put in a visual. But the code above, as I said, returns a table, so you'll not be able to use it, even if there's been a selection made in the slicer.
// Careful here: this returns a table
// so it can't be a measure!!! Measures
// never return tables, only scalar
// values.
[5 mejores productos] =
var vProdCount = SELECTEDVALUE( 'Top N'[Top N] )
var vResult =
TOPN(
vProdCount,
ADDCOLUMNS(
DimProducto[EnglishProductName],
"@Suma",
CALCULATE(
FactVentas[Ventas]
)
),
[@Suma]
)
RETURN
vResult
You can try the above... but this is not a measure. The code returns a table (as does yours), so I'm not sure what you're trying to achieve with this. If no selection has been made in the Top N table, then this will return nothing. And for such a selection to occur, the parameter table must be put in a visual. But the code above, as I said, returns a table, so you'll not be able to use it, even if there's been a selection made in the slicer.