Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

value comparison between two dates

Hello Community,   Hope you are well. I am struggling with dates comparison and I would appreciated if you could help me. I try to build a table that will show the value delta of two projects, br...
  • 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:

     

    You may create a calculated column or a measure as below.

    Calculated column:

    Result Column = 
    var edate = [ExtractionDate]
    var project = [Project]
    var year = [Year]
    var quarter = [Quarter]
    var _lastdate = 
    CALCULATE(
        MAX('Table'[ExtractionDate]),
        FILTER(
            ALL('Table'),
            [ExtractionDate]<edate&&
            [Project]=project&&
            [Year]=year&&
            [Quarter]=quarter
        )
    )
    var _val = 
    CALCULATE(
        SUM('Table'[Value]),
        FILTER(
            ALL('Table'),
            [ExtractionDate]=_lastdate&&
            [Project]=project&&
            [Year]=year&&
            [Quarter]=quarter
        )
    )
    return
    IF(
        ISBLANK(_lastdate),
        BLANK(),
        [Value]-_val
    )

     

    Measure:

    Result Measure = 
    var tab = 
    ADDCOLUMNS(
        'Table',
        "Result",
        var edate = [ExtractionDate]
        var project = [Project]
        var year = [Year]
        var quarter = [Quarter]
        var _lastdate = 
        CALCULATE(
            MAX('Table'[ExtractionDate]),
            FILTER(
                ALL('Table'),
                [ExtractionDate]<edate&&
                [Project]=project&&
                [Year]=year&&
                [Quarter]=quarter
            )
        )
        var _val = 
        CALCULATE(
            SUM('Table'[Value]),
            FILTER(
                ALL('Table'),
                [ExtractionDate]=_lastdate&&
                [Project]=project&&
                [Year]=year&&
                [Quarter]=quarter
            )
        )
        return
        IF(
            ISBLANK(_lastdate),
            BLANK(),
            [Value]-_val
        )
    )
    return
    SUMX(
        tab,
        [Result]
    )

     

    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.