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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.