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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
jdusek92
Advocate III
Advocate III

Different result CALCULATE and FILTER

Hello,

I am trying to achieve a "countif" column in a table, that will count the occurrences of rows ID in the whole table.

I tried these approaches:

 

FILTER = COUNTROWS(FILTER('Table','Table'[ID]=EARLIEST('Table'[ID])))
  • this works
 
CALCULATE = CALCULATE(COUNTROWS('Table'),'Table'[ID] = EARLIEST('Table'[ID]))
  • this does not calculate correctly
jdusek92_0-1620992679037.png

 

 I am wondering why CALCULATE is not working for this scenario. Could anybody explain, please?

 

 

Warm regards

Jakub

1 ACCEPTED SOLUTION
Anonymous
Not applicable

EARLIEST should be ditched. It's not recommended to use this function anymore. Use variables instead. CALCULATE does context transition (puts filters on all the rows) so it can't work here without extra directives. But at any rate, you should not use CALCULATE in calculated columns, especially in fact tables. Context transition is costly and will put the engine to a halt.

View solution in original post

2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

@jdusek92 @Anonymous is generally correct. The Excel equivalent functions can be found here, including COUNTIF:

Excel to DAX Translation - Microsoft Power BI Community



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

EARLIEST should be ditched. It's not recommended to use this function anymore. Use variables instead. CALCULATE does context transition (puts filters on all the rows) so it can't work here without extra directives. But at any rate, you should not use CALCULATE in calculated columns, especially in fact tables. Context transition is costly and will put the engine to a halt.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.