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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
instdes
Frequent Visitor

Count Rows by Year

Hi,

 

I am trying to count the number of rows I have by year.  The calculation I am using is below but it looks like it is counting all of my rows and not filtering by year because I don't have any events in 2005?  Any help would be greatly appreciated. 

 

2005Count = CALCULATE(COUNTROWS(Data), YEAR(Data[eventDate] = 2005))
 
Thanks.
1 ACCEPTED SOLUTION
foodd
Community Champion
Community Champion

The issue in your DAX expression is with the placement of the closing parenthesis in the CALCULATE function. You need to move the closing parenthesis for the YEAR function to the correct position. Make sure that the 'eventDate' column in the 'Data' table contains valid dates, and the year is extracted correctly by the YEAR function.

 

Here's the corrected DAX expression:

 

2005Count = CALCULATE(COUNTROWS(Data), YEAR(Data[eventDate]) = 2005)

 

 

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

You should ideally create a Calendar Table with a calculated column of Year.  Create a relationship (Many to One and Single) from the Event Date column to the Date column.  To your visual, drag Year from the Calendar Table.  Write this measure

Count = countrows(Data)

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
foodd
Community Champion
Community Champion

The issue in your DAX expression is with the placement of the closing parenthesis in the CALCULATE function. You need to move the closing parenthesis for the YEAR function to the correct position. Make sure that the 'eventDate' column in the 'Data' table contains valid dates, and the year is extracted correctly by the YEAR function.

 

Here's the corrected DAX expression:

 

2005Count = CALCULATE(COUNTROWS(Data), YEAR(Data[eventDate]) = 2005)

 

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors