Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Day function not referencing dates column

I am trying to run a DAX calculation to clean up my dates. I want to create an IF function that checks if a date is on the 1st of the month, and if it is, subtracts 1 day to put it at the end of the previous month. However, I find myself unable to reference my dates column using the day function. Here is the syntax I am trying to use:

Date (Corrected) = CALCULATE(IF(DAY("date")=1,DATEADD("Date",-1,DAY),"date"))

6 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      The problem is that the Day function isn't recognizing the name of my dates column. Unless i enclose it with a sum function first Day(Sum("date")). It only allows me to select calculated measures.

       

      • SpartaBI's avatar
        SpartaBI
        Community Champion

        Anonymous are you trying to create a measure or a calculated column? If it's a measure , then yes, you need to wrap any column with an aggregate. So, you could use:

         

        Date (Corrected) Measure =
        VAR _current_date =  SELECTEDVALUE('Table'[Date])
        RETURN
        IF(DAY(_current_date) = 1, _current_date - 1, _current_date)

         







              

        Showcase Report – Contoso By SpartaBI