Forum Discussion
neonguyen1803
3 years agoFrequent Visitor
Incremental Subtract
Dear all, I have a table below: Date CusID ProID Stock 13/10/2023 1 1 10 13/10/2023 1 2 5 13/10/2023 1 3 7 13/10/2023 2 1 13 13/10/2023 2 2 8 13/10/2023 2...
- 3 years ago
Hi neonguyen1803
Please refer to attached sample file with proposed calculated column solutionRemain Stock = VAR CurrentStock = 'Table'[Stock] VAR Change = SUMX ( FILTER ( CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[CusID], 'Table'[ProID] ) ), 'Table'[Date] < EARLIER ( 'Table'[Date] ) ), 'Table'[Stock] ) RETURN CurrentStock - Change - 3 years ago
neonguyen1803
Yes sure, here you goRemain Stock = VAR CurrentStock = 'Table'[Stock] VAR PreviousStock = SUMX ( TOPN ( 1, FILTER ( CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[CusID], 'Table'[ProID] ) ), 'Table'[Date] < EARLIER ( 'Table'[Date] ) ), 'Table'[Date] ), 'Table'[Stock] ) RETURN CurrentStock - PreviousStock
tamerj1
3 years agoCommunity Champion
Hi neonguyen1803
Please refer to attached sample file with proposed calculated column solution
Remain Stock =
VAR CurrentStock = 'Table'[Stock]
VAR Change =
SUMX (
FILTER (
CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[CusID], 'Table'[ProID] ) ),
'Table'[Date] < EARLIER ( 'Table'[Date] )
),
'Table'[Stock]
)
RETURN
CurrentStock - Change- neonguyen18033 years agoFrequent Visitor
It's really great. One more question, I just want subtract with nearlest day, example: 19/10/2023 will subtract 13/10/2023, 24/10/2023 subtract 19/10/2023. Please help me explain for extended question
- tamerj13 years agoCommunity Champion
neonguyen1803
Yes sure, here you goRemain Stock = VAR CurrentStock = 'Table'[Stock] VAR PreviousStock = SUMX ( TOPN ( 1, FILTER ( CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[CusID], 'Table'[ProID] ) ), 'Table'[Date] < EARLIER ( 'Table'[Date] ) ), 'Table'[Date] ), 'Table'[Stock] ) RETURN CurrentStock - PreviousStock- neonguyen18033 years agoFrequent Visitor
Thank you so much