Dax Function: DISTINCTCOUNTNOBLANK

Category: Aggregation functions

The DISTINCTCOUNTNOBLANK function in Power BI is a DAX function that counts the number of unique (distinct) non-blank values in a column. It extends the functionality of the DISTINCTCOUNT function by explicitly excluding blank values from the count, making it ideal for datasets where blanks are not meaningful.

Purpose:

  • To count unique non-blank values in a column.
  • To ensure that blank entries are ignored during aggregation.

Type of Calculations:

  • Performs deduplication while explicitly excluding blank values.

Practical Use Cases:

  1. Active Customer Count: Count unique active customers, excluding any missing customer IDs.
  2. Distinct Product Types: Count the number of unique products where blanks indicate missing or incomplete data.
  3. Survey Analysis: Count unique responses while ignoring unanswered (blank) entries.

DISTINCTCOUNTNOBLANK(<column>)</column>

ParameterTypeDescription
columnColumnThe column containing the values for which unique non-blank values are to be counted.

How Does DISTINCTCOUNTNOBLANK Dax Function Works?

  1.  
  1. Column Evaluation: The function evaluates all values in the specified column.
  2. Deduplication: Removes duplicate values.
  3. Exclude Blanks: Ignores blank values completely, ensuring only unique non-blank entries are counted.

Example:
For the following Sales table:

CustomerIDProduct
1A
2B
3 
1A

Using DISTINCTCOUNTNOBLANK(Sales[CustomerID]), the function returns 3 because blank entries are ignored, and the unique non-blank CustomerIDs are 1, 2, and 3.


What Does It Return?

The DISTINCTCOUNTNOBLANK function returns an integer representing the count of unique, non-blank values in the specified column.

When Should We Use It?

  • Deduplicating Non-Blank Entries: Useful for datasets where blanks are placeholders or irrelevant.
  • Avoiding Null Values: Helps in accurate reporting by ensuring blank or null values do not skew results.
  • Filtering Data for Analysis: Essential in scenarios where incomplete data should be excluded from the analysis.

Examples

Basic Usage

Count the number of unique products sold, excluding blanks:


UniqueProductsNoBlanks = DISTINCTCOUNTNOBLANK(Sales[Product])

Output: Returns 2, considering only unique non-blank products: A and B.

Column Usage

Count unique customer IDs in the dataset:


UniqueCustomerIDs = DISTINCTCOUNTNOBLANK(Sales[CustomerID])

Returns 3, as blank values are ignored.

Advanced Usage

Count unique customers based on filter conditions, ignoring blanks:


HighSpendingCustomers = DISTINCTCOUNTNOBLANK(FILTER(Sales, Sales[Revenue] &gt; 1000), Sales[CustomerID])

Result: Counts unique CustomerID values where revenue exceeds 1000, ignoring blanks.

Tips and Tricks

  • Automatic Blank Exclusion: You don’t need additional filters to exclude blanks—DISTINCTCOUNTNOBLANK does this automatically.
  • Combine with Filters: Use with CALCULATE or FILTER to refine the scope of the count.
  • Handling Blanks Explicitly: If blanks hold specific meaning in your dataset, consider using DISTINCTCOUNT instead.

Performance Impact of DISTINCTCOUNTNOBLANK DAX Function:

  • Efficiency: DISTINCTCOUNTNOBLANK is efficient but can slow down with very large datasets. Consider data modeling optimizations if performance is an issue.
  • Avoid Nested Functions: Avoid using it in deeply nested calculations to maintain performance.

Related Functions You Might Need

  • DISTINCTCOUNT: Counts all unique values in a column, including blanks.
  • COUNT: Counts numeric, non-blank values.
  • COUNTA: Counts all non-blank values in a column.
  • DISTINCT: Returns a table with distinct values from a column.

Want to Learn More?
For more information, check out the official Microsoft documentation for DISTINCTCOUNTNOBLANK. You can also experiment with this function in your Power BI reports to explore its capabilities.

If you’re looking to unlock the full potential of Power BI and take your data insights to the next level, our expert Power BI consulting services are here to help. Whether you need assistance with implementing advanced DAX functions like the ones discussed here, creating interactive dashboards, or optimizing your data models for better performance, our team of seasoned Power BI consultants is ready to provide tailored solutions for your business. Visit our Power BI Consulting page to learn more about how we can empower your organization with data-driven decisions.

1. What does DISTINCTCOUNTNOBLANK do in Power BI?

It counts the number of unique non-blank values in a column.

2. How is DISTINCTCOUNTNOBLANK different from DISTINCTCOUNT?

DISTINCTCOUNTNOBLANK excludes blank values from the count, while DISTINCTCOUNT includes them.

3. Does DISTINCTCOUNTNOBLANK count blank values?

No, it automatically excludes blanks from the count.

4. Can I use DISTINCTCOUNTNOBLANK with filters?

Yes, it works dynamically with filters and can be combined with CALCULATE for custom conditions.

5. Is DISTINCTCOUNTNOBLANK suitable for large datasets?

Yes, but ensure columns are optimized for best performance.