Forum Discussion

ldwf's avatar
ldwf
Helper V
3 years ago
Solved

RCustomDAXFilter logic

Hello, I have a query parameter (not report parameter) where the user selects a date from the dropdown.  I want to be able to retrieve the past 13 months of data based on the date selected in the pro...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi ldwf ,

    You need a calendar table with no relationship between the fact table:

    Then please new a measure:

    Measure = 
    VAR _max_date = MAX('Calendar'[Date])
    VAR _min_date = EDATE(_max_date,-13)
    VAR _filter = IF(MAX('Table'[Date])>_min_date&&MAX('Table'[Date])<=_max_date,1)
    RETURN
    _filter

    If the visual has a date axis, you can use it as a filter.

    For a single measure, you can pass these two variables into the filter parameter like this.

    Sales = 
    VAR _max_date = MAX('Calendar'[Date])
    VAR _min_date = EDATE(_max_date,-13)
    VAR _sales = CALCULATE(SUM('Table'[Sales]),'Table'[Date]>_min_date&&'Table'[Date]<=_max_date)
    RETURN
    _sales

     

    Best Regards,
    Gao

    Community Support Team

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly -- How to provide sample data