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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How COUNTROWS works in this DAX?

rank = COUNTROWS(FILTER(Cars,EARLIER(Cars[Rev])>Cars[Rev]))+1

 

cars.JPG

 

For this DAX, I know that the FILTER will remove any value in Rev. column larger than $950, so they are $0, $240, and $500 in this table.

 

Then how does COUNTROWS work here? 

 

I assume the COUNTROWS work in this way:

 

The COUNTROWS will traverse every number in the list and count how many rows meets the argument.  

 

car3.JPG

For $950, 3 rows meet the criteria (less than $950)

 

For $1170, 4 rows meet the criteria (less than $1170)

 

After plus 1, $950 will be ranked as 4th and $1170 will be ranked as 5th in the list which ranked numbers from small to large eventually. 

 

Is my understanding correct?

 

Thank you in advance! 

 

1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

You understanding of countrows() and earlier() is correct. The countrows() function will count the rows(values) which is less than currect rows(earlier(Cars[Rev])). And if you want to reverse the rank, you can just change ">" with "<" like below:

rank = COUNTROWS(FILTER(Cars,EARLIER(Cars[Rev])<Cars[Rev]))+1

Community Support Team _ Jimmy Tao

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

3 REPLIES 3
v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

You understanding of countrows() and earlier() is correct. The countrows() function will count the rows(values) which is less than currect rows(earlier(Cars[Rev])). And if you want to reverse the rank, you can just change ">" with "<" like below:

rank = COUNTROWS(FILTER(Cars,EARLIER(Cars[Rev])<Cars[Rev]))+1

Community Support Team _ Jimmy Tao

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

v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

I think the blog below explain the function "earlier" very well, you may refer to the blog:

https://exceleratorbi.com.au/earlier-vs-earliest-dax/

 

Community Support Team _ Jimmy Tao

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

Anonymous
Not applicable

Hi, I feel like my question is more related to COUNTROWS instead of EARLIER. Sorry for misleading.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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