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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

M Code count number of records for year to date

Hello, I would like to write M Code to count the number of records (in this case number of surveys) for the Year to Date. How would I write this? Thanks in advance.

Screenshot (88).png

7 REPLIES 7
Peter_Beck
Resolver II
Resolver II

If you use that fucntion you can't hard-code a year value. Instead, you need to use a column in your data that contains valid dates.

 

TOTALYTD(<expression>,<dates>[,<filter>][,<year_end_date>])

 

So if you have a column that contains some transaction date for your data, put that column in where you currently have 2023.

 

Cheers,

 

Peter

Anonymous
Not applicable

Okay, when I do this (first photo), I find I get the same count as Month to Date. Note When I do [Date].[Year](second photo) in the second function it cannot display the video. 

Screenshot (92).pngScreenshot (94).png

I can't evaluate your data, but I think the problem is that (looking at your first screen-shot), you are attempting to accumulate a value of [Count of Survey Number By Month]. Try instead to base the calculation on counting the raw "Survey Number".

 

Consider asking this in the DAX forum, there are a lot of experts over there.

 

Cheers,

 

Peter 

Peter_Beck
Resolver II
Resolver II

Hi -

 

I am not sure I would use M to do that, have you considered creating a measure using DAX?

 

Cheers,

 

Peter

Anonymous
Not applicable

Well I guess I want to create a measure. That would be M Code, right?

M-code is more for the manipulation of the "shape" of your data - splitting tables in two, adding or renaming columns, that kind of thing. 

 

To create a measure you want to use DAX. Take a look at the TOTALYTD function.

 

Hope this helps,

 

Peter

Anonymous
Not applicable

Okay, thanks. Why doesn't my DAX code here seem to be working? Screenshot (90).png

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.

Top Kudoed Authors