Forum Discussion

ArchStanton's avatar
ArchStanton
Power Participant
2 years ago
Solved

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:

 

Any ideas why?

Thanks

 

  • ArchStanton's avatar
    ArchStanton
    2 years ago

    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"))

10 Replies

  • 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")

    • ArchStanton's avatar
      ArchStanton
      Power Participant

      I also get this error with your amendment:

       

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

       

      • Dangar332's avatar
        Dangar332
        Resident Rockstar

        hi, ArchStanton 

         

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

        so clarify what you want?

    • ArchStanton's avatar
      ArchStanton
      Power Participant

      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"))

       

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

    • ArchStanton's avatar
      ArchStanton
      Power Participant

      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")

       

       

      • ChiragGarg2512's avatar
        ChiragGarg2512
        Solution Sage

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