Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
cleenfeet
New Member

Slicer selected value is not working in filter as a variable

Hello all, 

 

I'm new to Power BI. As I learn, this community has been extremely helpful. 

 

I'm stuck on a problem that I cannot solve and I haven't been able to find a solution on any forums. I'm trying to countrows based on slicer selection. 

 

Sample table

 

Name / Product/ Price

John/B/20

Mike/C/15

Jule/A/10

Sarah/B/20

Jordan/D/20

John/C/15

Sarah/A/10

John/A/10

 

Slicer is the name column. When I click on that slicer, I want it to show me the number of rows. So for instance, if I click John, it will return 3. If I click Sarah, it will return 2. I checked the ouput of selectedvalue of this is the correct name. 

 

So here is the forumla I've tried:

 

Measure =

VAR Selction = SELECTEDVALUE ('Table'[Name])
RETURN
CALCULATE (Countrows(Table), Table[Name]=Selection)

 This returns a number that I cannot figure out the meaning. If I replace "Selection" variable with "John" in the equation, it gives me the correct output. I've actually tried "COUNT" functions that work as well. None of them work with this variable from the SELECTEDVALUE function. Any help would be much appreciated!

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @cleenfeet ,

You can use the Countx function

https://docs.microsoft.com/en-us/dax/countx-function-dax

Here are the steps you can follow:

1. Create measure.

Measure =
var _selectname=SELECTEDVALUE('Table'[Name])
return
COUNTX(FILTER(ALL('Table'),'Table'[Name]=_selectname),[Name])

2. Result:

vyangliumsft_0-1653484771464.png

If you need pbix, please click here.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi  @cleenfeet ,

You can use the Countx function

https://docs.microsoft.com/en-us/dax/countx-function-dax

Here are the steps you can follow:

1. Create measure.

Measure =
var _selectname=SELECTEDVALUE('Table'[Name])
return
COUNTX(FILTER(ALL('Table'),'Table'[Name]=_selectname),[Name])

2. Result:

vyangliumsft_0-1653484771464.png

If you need pbix, please click here.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Nathaniel_C
Community Champion
Community Champion

Hi @cleenfeet ,

See my picture, to get these results, please use this measure:

Count = COUNTROWS(ALLSELECTED('Table'))


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

 

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.