Forum Discussion

lucy_wilshaw's avatar
lucy_wilshaw
New Member
4 years ago
Solved

Rolling Date Measure for Power BI

Hi,   I would like to set up a new date measure in Power BI desktop using the DAX code. I currently have it set up to "Date = CALENDAR (DATE(2012,1,1), DATE(2020,12,31))" but would like to change i...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi lucy_wilshaw ,

     

    I think you want to filter out the data of recent months from a starting date, the starting date and the number of months are both selected by the slicer.

     

    Sample data

     

    Here's my solution.

    1.Create a calendar table.

     

    Date = CALENDAR (DATE(2012,1,1), DATE(2020,12,31))

     

     There's no relationship between the calendar table and the main table.

     

    2.Create a what-if parameter, set maximum is 120.

     

     

     

    3.Create a measure. Put it into the page level visual and set show items when the value is 1.

    Measure = var _start=SELECTEDVALUE('Date'[Date])
    var _num=SELECTEDVALUE('Parameter'[Parameter])
    return IF(MAX('Table'[Date])>=_start&&MAX('Table'[Date])<=EOMONTH(_start,_num-1),1)

     

    Now you can filter date and month number.

     

     

    Best Regards,

    Stephen Tao

     

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