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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
gaccardo
Advocate II
Advocate II

Off-by-One Error using COUNTX() and ALL()

I have an issue when using COUNTX () with the ALL() function.  The value returned is the actual number of rows plus one.  I've verified this with a bunch of tables, and I've got a solution, specifically using the ALLNOBLANKROW() function instead of ALL().  What I don't know is why this is necessary or if this is a proper pattern to use for solving counting all the rows that meet a particular condition.  Any suggestions would be appreciated.

This DAX returns the correct answer, but I don't know why or if this is a correct pattern to use.

All Requirements without User Stories =
  VAR counter =
    COUNTX(
      ALLNOBLANKROW('Requirement'),
      IF(
        [Count of Related User Stories] < 1,
        1,
        BLANK()
      )
    )

  RETURN
    IF (
      ISBLANK (counter),
      0,
      counter
    )

This DAX returns a number that is the correct number plus one.  Why?

All Requirements without User Stories =
  VAR counter =
    COUNTX(
      ALL('Requirement'),
      IF(
        [Count of Related User Stories] < 1,
        1,
        BLANK()
      )
    )

  RETURN
    IF (
      ISBLANK (counter),
      0,
      counter
    )
1 ACCEPTED SOLUTION
v-cherch-msft
Microsoft Employee
Microsoft Employee

Hi @gaccardo

 

You may refer to ALLNOBLANKROW Function and ALL Function. Here is the article for you. Show a sample as below:

We can get the correct count of rows with ALLNOBLANKROW Function as it returns all rows but the blank row from the parent table of a relationship.

 

1.png3.png

 

 

Regards,

Cherie

 

 

 

 

Community Support Team _ Cherie Chen
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
v-cherch-msft
Microsoft Employee
Microsoft Employee

Hi @gaccardo

 

You may refer to ALLNOBLANKROW Function and ALL Function. Here is the article for you. Show a sample as below:

We can get the correct count of rows with ALLNOBLANKROW Function as it returns all rows but the blank row from the parent table of a relationship.

 

1.png3.png

 

 

Regards,

Cherie

 

 

 

 

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you @v-cherch-msft.  That was an excellent explanation and a very informative article.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Users online (4,944)