Forum Discussion
topn dax for negative values
- 6 years ago
Anonymous
Sort Ascending should give you top negative numbers. Or Top means all near to 0. Then have a filter of <0 in your measure
order
(Optional) A value that specifies how to sort orderBy_expression values, ascending or descending:value alternate value Description 0 (zero) FALSE Sorts in descending order of values of order_by.
This is the default value when order parameter is omitted.1 TRUE Ranks in ascending order of order_by. Or use rank
For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale - 6 years ago
Hi, Anonymous
You may create a what-if parameter as below.
Then you may create a measure as below.
IsDisplay = var _topn = SELECTEDVALUE(Parameter[Parameter]) var _name = SELECTEDVALUE('Table'[Name]) var tab = ADDCOLUMNS( ALLSELECTED('Table'), "Rank", RANKX( ALLSELECTED('Table'), 'Table'[Value] ) ) var _rank = SUMX( FILTER( tab, [Name] = _name ), [Rank] ) return IF( _rank<=_topn, 1,0 )Finally you need to put the measure in the visual level filter of a table visual. Here is the result.
Best Regards
Allan
Hi, Anonymous
You may create a what-if parameter as below.
Then you may create a measure as below.
IsDisplay =
var _topn = SELECTEDVALUE(Parameter[Parameter])
var _name = SELECTEDVALUE('Table'[Name])
var tab =
ADDCOLUMNS(
ALLSELECTED('Table'),
"Rank",
RANKX(
ALLSELECTED('Table'),
'Table'[Value]
)
)
var _rank =
SUMX(
FILTER(
tab,
[Name] = _name
),
[Rank]
)
return
IF(
_rank<=_topn,
1,0
)
Finally you need to put the measure in the visual level filter of a table visual. Here is the result.
Best Regards
Allan