Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
I created a virtual table with rankings. then I created a real table called TopN using Generateseries to create a list of int numbers and made a slicer. last I create a variable called SelectedN .
the TopN Table = GENERATESERIES(5,30,5)
Hi @jimmyhua
The behavior you're observing is due to filter context and how the SELECTEDVALUE function works in DAX. Let's analyze the situation and resolve the issue step by step:
The SELECTEDVALUE function depends on the filter context applied to the column. When you use a slicer to filter the TopN Table, the selection is applied to that specific column. However, if you reference SELECTEDVALUE(TopNTable[Value]) in a different table's measure (e.g., your virtual RankedTable), the filter context from the slicer may not propagate to that measure or visual.
This is why SelectedN is blank in some scenarios, but when you hardcode a value like 15 or 10, the filter works as expected.
To fix this, ensure the slicer's filter context is explicitly passed to your calculation. Here’s how:
Use MAX instead of SELECTEDVALUE, which ensures that the slicer's selection is retrieved correctly, even if used outside the slicer's visual context:
VAR SelectedN = MAX(TopNTable[Value])
Use the SelectedN variable directly in your filter condition:
RETURN
FILTER(
RankedTable,
[RankByBL] <= SelectedN
)
If SelectedN is still blank, verify that the slicer is affecting the filter context. Create a debugging measure to display the current value of SelectedN:
Debug SelectedN = MAX(TopNTable[Value])
Add this measure to a card visual to confirm the slicer selection. If this returns blank:
To ensure that the slicer's selection dynamically filters the RankedTable, follow these steps:
Confirm that TopNTable[Value] is directly used in the slicer.
Verify that the TopN Table exists in the data model and isn't only a disconnected table. If it’s disconnected, you may need to adjust the logic or use a measure like this:
SelectedN =
CALCULATE(
MAX(TopNTable[Value]),
ALLSELECTED(TopNTable)
)
Ensure the slicer is set to Single Select mode for proper behavior.
Here’s your final measure incorporating the solutions:
Ranked Table Filter =
VAR SelectedN = MAX(TopNTable[Value]) // Ensure selection is retrieved
RETURN
FILTER(
RankedTable,
[RankByBL] <= SelectedN
)
Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂
Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
YouTube: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS
Hi PooJara,
Thank you for the detail response. yes. the table would react to MAX(TopNTable[Value]), however, since it gives the largest selection, how it can help me to use it when I want to select a lower value?
Thanks for the reply from Poojara_D12.
Hi @jimmyhua ,
Please use the following DAX formula:
Ranked Table Filter =
VAR SelectedN = IF(HASONEVALUE('TopN Table'[Value]),MAX('TopN Table'[Value]),MIN('TopN Table'[Value]))
RETURN
FILTER(
'RankedTable',
[Rank] <= SelectedN
)
Result:
Best Regards,
Zhu
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks for the reply from lbendlin.
Hi @jimmyhua ,
The SELECTEDVALUE function returns the value when the context for columnName has been filtered down to a single distinct value; otherwise, it returns an alternative value. If no alternative value is provided and the slicer is not filtered, SELECTEDVALUE returns null when there is no single distinct value in the context.
If the TopNTable you create has only one value, then you don't need to use a slicer.
Best Regards,
Zhu
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
You cannot meaningfully create calculated tables from measures or slicers. Only works the other way round.
User | Count |
---|---|
16 | |
13 | |
12 | |
11 | |
11 |
User | Count |
---|---|
19 | |
15 | |
14 | |
11 | |
10 |