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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors