Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Dynamic comparison tables using separate date filters

Hi, I have a main facts table that includes date, costs, clicks etc.  I also have a separate dates table with a relationship setup with facts table, with elements such as date, YY_WW, YY_MM I wa...
  • 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.

    Table:

     

    Metrics:

     

    Calendar 1(a calculated table):

    Calendar 1 = CALENDARAUTO()

     

    Calendar 2(a calculated table):

    Calendar 1 = CALENDARAUTO()

     

    There is no relationship between tables. You may create two measures as below.

    Period 1 totals = 
    IF(
        HASONEVALUE(Metrics[Metric]),
        IF(
            SELECTEDVALUE(Metrics[Metric])="Cost",
            CALCULATE(
                SUM('Table'[Cost]),
                FILTER(
                    ALL('Table'),
                    [Date] in DISTINCT('Calendar 1'[Date])
                )
            ),
            CALCULATE(
                SUM('Table'[Click]),
                FILTER(
                    ALL('Table'),
                    [Date] in DISTINCT('Calendar 1'[Date])
                )
            )
        )
    )
    Period 2 totals = 
    IF(
        HASONEVALUE(Metrics[Metric]),
        IF(
            SELECTEDVALUE(Metrics[Metric])="Cost",
            CALCULATE(
                SUM('Table'[Cost]),
                FILTER(
                    ALL('Table'),
                    [Date] in DISTINCT('Calendar 2'[Date])
                )
            ),
            CALCULATE(
                SUM('Table'[Click]),
                FILTER(
                    ALL('Table'),
                    [Date] in DISTINCT('Calendar 2'[Date])
                )
            )
        )
    )

     

    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.