Forum Discussion

Evan_Power_Bi's avatar
Evan_Power_Bi
Frequent Visitor
4 years ago
Solved

Subtracting Values from the same column into new column based on dates

I have  Date       | Material | Last Week Date | S | F | 1/8/2022  iron         1/1/2022            1.00 .99 1/15/2022  iron         1/8/2022          1.10  1.01   Based on the date and last wee...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Evan_Power_Bi ,

     

    Having already seen the video, if any material corresponds to a unique date and your expected output is such, try this calculation column.

    Diff_S = 
    VAR _date = 'Table'[Date]
    VAR _material = 'Table'[Material]
    VAR _cur_s =
        CALCULATE (
            MAX ( 'Table'[S] ),
            FILTER ( 'Table', 'Table'[Date] = _date && 'Table'[Material] = _material )
        )
    VAR _pre_date =
        CALCULATE (
            MAX ( 'Table'[Date] ),
            FILTER ( 'Table', 'Table'[Material] = _material && 'Table'[Date] < _date )
        )
    VAR _pre_s =
        CALCULATE (
            MAX ( 'Table'[S] ),
            FILTER ( 'Table', 'Table'[Date] = _pre_date && 'Table'[Material] = _material )
        ) + 0
    VAR _diff =
        IF ( _pre_s <> 0, _cur_s - _pre_s, 0 )
    RETURN
        _diff

    The PBIX file is attached for reference.

     

    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