Forum Discussion

Mahamood0218's avatar
Mahamood0218
Helper II
4 years ago
Solved

How to get selected month from date table

Hi Experts , i want create a dax function for selected month date  above pic is sample data Requiremnt  if i select filter as  year 2022 dax fucntion (Dateselected month) should be like as ...
  • BA_Pete's avatar
    4 years ago

    Hi Mahamood0218 ,

     

    If your date is always the first of May on the year that you select, then the DAX for your card display would be something like this:

    _selectionStartDate =
    VAR __year = SELECTEDVALUE(calendar[year])
    RETURN
    FORMAT(
        DATE(__year, 05, 01),
        "dd-MM-yyyy"
    )

     

    Pete

  • BA_Pete's avatar
    BA_Pete
    4 years ago

    Hi Mahamood0218 ,

     

    No, the month in this example is fixed, it's only the year that is dynamic based on the selected slicer value.

    If you want it to always default to the first of the current month, then you would use something like this:

    _DateSelectedMonthStart = 
    VAR __year = SELECTEDVALUE(DimDate[Year])
    VAR __month = MONTH(TODAY())
    RETURN
    FORMAT(
        DATE(__year, __month, 01),
        "dd-MM-yyyy"
    )

     

    Pete