Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
After having read this post https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/3... I was wondering why this is not working.
I´ve first made a parameter Top N which has
Solved! Go to Solution.
// 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.
To be frank, I don't understand why the version with SELECTEDVALUE under TOPN would not work, either. I would say it does work but we probably don't fully understand why it returns what it returns. Please note that SELECTEDVALUE will return BLANK (=0) if there are no selections made in the slicer or if there are many items selected. And as I already said, you're trying to return a table and this will never work on the PBI canvas. Even more, you can't expect that such a calculated table will constantly re-calc when you change the selections in the slicer. Calculated tables are static by design and no selection on the canvas can affect them. So, if you think that your table should re-calc and SELECTEDVALUE will return the selection from the slicer... well, you are very much mistaken.
Thanks a lot, actually, yes, a table is what I expect. Ehat I don´t actually understand is why I need to pass throgh a variable instead of using the selectedvalue in the topn directly.
Regards!!! and have a fine day.
// 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.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
18 | |
15 | |
12 | |
11 | |
8 |
User | Count |
---|---|
24 | |
18 | |
12 | |
11 | |
10 |