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
Oros
Post Prodigy
Post Prodigy

DistincCount with Filter

Hello,
 
I have a measure that works using DISTINCOUNTNOBLANK. How do you add a filter to this measure, for example, ONLY distinct count
"the product number that starts in number 1 and 2"? Thanks.
 
TOTAL ITEMS = DISTINCTCOUNTNOBLANK(Product_Table[product number])
1 ACCEPTED SOLUTION
speedramps
Community Champion
Community Champion

The solution will works. Please try copy it carefully. Then click accept solution. Thanks.

Answer =
VAR tempfile = FILTER('yourtable',NOT LEFT('yourtable'[PRODUCT NUMBER],1) IN {"2","3"})
RETURN
CALCULATE(
DISTINCTCOUNT('yourtable'[PRODUCT NUMBER]),
tempfile)

 

speedramps_1-1697923421518.png

 

 

View solution in original post

10 REPLIES 10
parry2k
Super User
Super User

@speedramps great advice and I also have a small advice for you. I hope don't mind. When you paste a DAX or M code, instead of pasting it as text, use the insert/edit code sample button on the editor and paste the code there. It differentiates the code from the rest of the text/message.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@Oros the syntax seems to be correct, can you share the expression you are using?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

speedramps
Community Champion
Community Champion

Try this ..

Answer =
VAR felixfile = FILTER('yourtable',NOT LEFT('yourtable'[PRODUCT NUMBER],1) IN {"2","3"})
RETURN
CALCULATE(
DISTINCTCOUNT('yourtable'[PRODUCT NUMBER]),
felixfile)


Thanks for the clear description of the problem with example data. I wish everyone did that!

Remember we are unpaid volunteers. So please click the thumbs up and the [accept as solution] button to leave kudos. 

If you give someone a fish then you only give them one meal, but if you teach them how to fish then they can feed themselves and teach others for a lifetime.  This is how I try answer Power BI and DAX questions with clear examples so you learn techniques.

One question per ticket please. If you need to extend your request then please raise a new ticket.

You will get a quicker response and each volunteer solver will get the kudos they deserve. Thank you ! 

If you quote @speedramos in your next tickets then I will then receive an automatic notification, and will be delighted to help you again.

Please click the thumbs up and the [accept as solution] button. 

Hi @speedramps ,

 

I am getting an error "the syntax for 'RETURN' is incorrect.

speedramps
Community Champion
Community Champion

The solution will works. Please try copy it carefully. Then click accept solution. Thanks.

Answer =
VAR tempfile = FILTER('yourtable',NOT LEFT('yourtable'[PRODUCT NUMBER],1) IN {"2","3"})
RETURN
CALCULATE(
DISTINCTCOUNT('yourtable'[PRODUCT NUMBER]),
tempfile)

 

speedramps_1-1697923421518.png

 

 

Hi @speedramps ,

 

Thanks!!!

speedramps
Community Champion
Community Champion

Thanks @Oros for accepting the solution.

Please quote @speedramps in any future questions and I will will receive an automated notification and try resolve it.
Always try provide example input data, desired output and clear step by step description. Provide input date as a table and not a picture so we can import it and build a soluton. Thanks

 

speedramps
Community Champion
Community Champion

We want to help you but your description is too vaugue. Please write it again clearly.

Please DON'T copy & paste your DAX that does not work and expect us to fathom what you want to do. That would be crazy. 😀

Please just give a simple non technical functional decscription of what you want, then let us suggest the DAX. Thank you.

Provide example input data as table text (not a screen print) so we can import the data to build a solution for you.
Also provide the example desired output, with a clear description of the process flow.

Remember not to share private data ... we don't want you to get into trouble. 😧

Take time and care to use the same table and field names in the input, output and description so we can understand your problem and help you.

You will get a quick response if you put time, care and effort into writing clear problem descriptions.

Vaugue descriptions can waste your time and ourtime.

Look foward to helping you when the above information is forthcoming

Hi @speedramps,

 

Thank you for your comment.

 

I have a sample table with only one column like this.  What measure to use to count the number of distinct products, EXCLUDING products that start in number 2 and number 3?  Thanks again.

PRODUCT NUMBER
10023
10024
10025
20018
20019
20020
30009
30010

That should do it:

Distinct count =
CALCULATE(DISTINCTCOUNT('Table'[PRODUCT NUMBER]),LEFT('Table'[PRODUCT NUMBER]) <>"2" && LEFT('Table'[PRODUCT NUMBER]) <>"3")
 

Daniel_PowerBI_0-1697924011730.png

 

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.