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
kendall
Helper I
Helper I

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

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

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

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

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.

Top Solution Authors
Top Kudoed Authors