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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
ArchStanton
Impactful Individual
Impactful Individual

DatesYTD Error

Hi,

 

I want to use DatesYTD instead of Total YTD because DatesYTD accepts more filters. I want to filter on the Created on date being after 31/03/2020

 

The following code is not working:

 

Closed Cases YTD2 = CALCULATE(
                        DATESYTD(Date2[Dates],"31-3"),
                        'Cases'[Created On] > "31/03/2020",
                        'Cases'[statecode] = "Resolved")

 

I'm getting this error:

 

ArchStanton_0-1698403437574.png

Any ideas why?

Thanks

 

1 ACCEPTED SOLUTION

I've managed to fix it, thanks for your help anyway!

 

TotalYTD does allow multiple filters contrary to what Ive been told:

 

Closed Cases YTD2 = CALCULATE(
    TOTALYTD(COUNT('Cases'[Case Number]),'Cases'[Resolution Date],"31/03"),
    'Cases'[statecode] = "Resolved",
    'Cases'[Created On] > DATEVALUE("31/3/2020"))

View solution in original post

10 REPLIES 10
marcelsmaglhaes
Super User
Super User

Hey @ArchStanton 
You can't compare date with values of type text. In your measure you do that in this part: 

'Cases'[Created On] > "31/03/2020",

You need convert the text into date. Try  'Cases'[Created On] > DATEVALUE("3/31/2020")


Regards,
Marcel Magalhães
Microsoft Power BI Official Partner
MCT | Certified PL-300 Power BI

If I've helped, don't forget to mark my post as a solution!



I've managed to fix it, thanks for your help anyway! TotalYTD does allow multiple filters contrary to what Ive been told:

 

Closed Cases YTD2 = CALCULATE(
    TOTALYTD(COUNT('Cases'[Case Number]),'Cases'[Resolution Date],"31/03"),
    'Cases'[statecode] = "Resolved",
    'Cases'[Created On] > DATEVALUE("31/3/2020"))

 

I also get this error with your amendment:

 

ArchStanton_0-1698404541918.png

Closed Cases YTD2 = CALCULATE(
                        DATESYTD(Date2[Dates],"31-3"),
                        'Cases'[Created On] > DATEVALUE("3/31/2020"),
                        'Cases'[statecode] = "Resolved")

 

hi, @ArchStanton 

 

datesytd()  funcyion only give set of group of date not one by one 

so clarify what you want?

As I've posted to the other helpers on this issue, the issue is now fixed.

Appreciate your help anyway!

I want to add an extra filter to this code, namely = created on> 31 Mar 2020

 

 

Closed Cases YTD = CALCULATE(
    TOTALYTD(COUNT('Cases'[Case Number]),'Cases'[Resolution Date],"31/03"),
    'Cases'[statecode] = "Resolved")

 

YTD does not allow me to add additional filters, so i thought DatesYTD would work instead

 

ChiragGarg2512
Solution Sage
Solution Sage

@ArchStanton , Its comparing the type date with type text which is creating the problem. Instead of "31/03/2020" write Date(2020, 3, 31).

Thanks, I did that, please see the code and I know get a different error (see below code)

 

Closed Cases YTD2 = CALCULATE(
                        DATESYTD(Date2[Dates],"31-3"),
                        'Cases'[Created On] > DATE(2020,3,31),
                        'Cases'[statecode] = "Resolved")

 

ArchStanton_0-1698404326506.png

 

@ArchStanton Calculate function returns a single value, so providing it with dates ytd give it multiple values. try using CALCULATETABLE.

I've managed to fix it, thanks for your help anyway!

 

TotalYTD does allow multiple filters contrary to what Ive been told:

 

Closed Cases YTD2 = CALCULATE(
    TOTALYTD(COUNT('Cases'[Case Number]),'Cases'[Resolution Date],"31/03"),
    'Cases'[statecode] = "Resolved",
    'Cases'[Created On] > DATEVALUE("31/3/2020"))

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.