Forum Discussion

trt18-sistemas's avatar
trt18-sistemas
Icon for Advocate IV rankAdvocate IV
6 years ago
Solved

Error using slicer to filter between start and end dates

Hi there,   I'd like to report a error at Power BI Desktop. I have one table (Vagas) that contains a list of Vagas with starting and ending dates (Data de Criação e Data de Extinção, respectivelly...
  • v-alq-msft's avatar
    6 years ago

    Hi, trt18-sistemas 

     

    Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

    Table:

     

    Calendar(a calculated table):

    Calendar = CALENDARAUTO()

     

    You may create calculated columns and a measure as below.

    Calculated column:

    Calendar Year Month = YEAR('Calendar'[Date])*100+MONTH('Calendar'[Date])
    Start Year Month = YEAR('Table'[Start Date])*100+MONTH('Table'[Start Date])
    End Year Month = YEAR('Table'[End Date])*100+MONTH('Table'[End Date])

     

    Measure:

    Visual Control = 
    var _yearmonth = SELECTEDVALUE('Calendar'[Calendar Year Month])
    var tab = 
    ADDCOLUMNS(
        'Table',
        "flag",
        IF(
            ISBLANK([End Year Month]),
            IF(
                [Start Year Month]<=_yearmonth,
                1,0
            ),
            IF(
                [Start Year Month]<=_yearmonth&&
                [End Year Month]>=_yearmonth,
                1,0
            )
        )
    )
    return
    SUMX(
        tab,
        [flag]
    )

     

    Finally you may put the measure in the visual level filter and use the year-month column from 'Calendar' table to filter the result.

     

    Best Regards

    Allan

     

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