Forum Discussion

NJ81858's avatar
NJ81858
Helper IV
3 years ago

Date Measure

Hello, 

 

I am trying to put together a measure that will give me a date range from the beginning of the year to the end of the user selected month. For example if a user selects July, I want the data from January 1 through July 31. This is what I have so far for my measure that will assign each day in that dynamic range with a 1 so that I can place a filter on all of my visuals to only show data that has a 1 as the value:

 

The issue with it in its current state is that no matter what month the user selects, it displays a 1 for every date. I just am not sure where my logic is going wrong in the measure, so any help would be appreciated!

8 Replies

  • Mikelytics's avatar
    Mikelytics
    Resident Rockstar

    Hi NJ81858 

     

    Please try the formula

     

    DATESYTD(DimDate[Date])

     

    DATESYTD function (DAX) - DAX | Microsoft Learn

     

     

     

    Best regards

    Michael

    -----------------------------------------------------

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your thumbs up!

    @ me in replies or I'll lose your thread.

    • Mikelytics's avatar
      Mikelytics
      Resident Rockstar

      Another option could be:

       

      DATESBETWEEN=
      
      var _lastdate = -> your code
      var _firstdate = -> your code
      
      RETURN
      
      DATESBETWEEN(Dates[Date],var _firstdate,var _lastdate)

       

      DATESBETWEEN function (DAX) - DAX | Microsoft Learn

       

      Best regards

      Michael

      -----------------------------------------------------

      If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your thumbs up!

      @ me in replies or I'll lose your thread.

      • NJ81858's avatar
        NJ81858
        Helper IV

        Mikelytics 

         

        When I try the DATESYTD function and put it in a table, it gives me the error that says "Calculation error in measure: A table of multiple values was supplied where a single value was expected."

         

        When I try the DATESBETWEEN function, it only returns the first value in the date table, that being, 1/1/2022, no matter what month I choose as my 'Selected Month' that the end date is supposed to be based on.