Forum Discussion
Subtracting Values from the same column into new column based on dates
- Anonymous4 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 _diffThe PBIX file is attached for reference.
Best Regards,
Gao
Community Support TeamIf 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
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