Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

filter when there is no value

I've got 3 tables   CaseID   start case   end case   start prod   end prod 1   1-1-2020   31-7-2020   1-1-2020   31-5-2020 2   1-2-2020   30-6-2020   1-3-2020   30-4-2020  ...
  • v-alq-msft's avatar
    5 years ago

    Hi, Anonymous 

     

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

    Table1:

    Table2:

    Calendar(a calculated table):

    Calendar = 
    ADDCOLUMNS(
        CALENDARAUTO(),
        "YYYY-MM",
        FORMAT([Date],"yyyy-MM")
    )

     

    Relationship:

     

    You may create a measure as below.

    Result = 
    var tab = 
    ADDCOLUMNS(
        Table1,
        "Re",
        var caseid = [CaseID]
        var s = [Start Prod]
        var e = [End Prod]
        var t1 = 
        CALCULATETABLE(
            DISTINCT('Calendar'[YYYY-MM]),
            FILTER(
                ALL('Calendar'),
                [Date]>=s&&
                [Date]<=e
            )
        )
        var t2 = 
        SELECTCOLUMNS(
                ADDCOLUMNS(
                    FILTER(
                       ALL(Table2),
                       [CaseID]=caseid
                    ),
                    "YM",
                    FORMAT([Date],"yyyy-MM")
                ),
                "YM",
                [YM]
        )
        return
        CONCATENATEX(
            FILTER(
                t1,
                NOT([YYYY-MM] in t2)
            ),
            [YYYY-MM],
            ","
        )
    )
    return
    CONCATENATEX(
        tab,
        [Re],
        ","
    )

     

    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.