cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Subtracting rows based on another column category

Hello, 

I would like to create a new column that would subtract the row values in 'FH' based on the 'Product'. The sample data set and corresponding expected output is as shown below. Kindly help.
Thanks.

ProductFHExpected Outcome
A20000
A50003000
A90004000
B25000
B60003500
B100004000

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Champion
Community Champion

Re: Subtracting rows based on another column category

@Zabeer 

 

Try this

 

Output = 
var _CurrentProduct=NewTable[Product]
var _PreviousFH= MAXX(FILTER(NewTable,NewTable[FH]<EARLIER(NewTable[FH]) && NewTable[Product]=_CurrentProduct),NewTable[FH])
var _result=NewTable[FH]-_PreviousFH
return IF(ISBLANK(_PreviousFH),0,_result)

 

Capture.JPG



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂

View solution in original post

3 REPLIES 3
Highlighted
Super User II
Super User II

Re: Subtracting rows based on another column category

Hi @Zabeer 

try a column

Expected Outcome = 
var _prevVal = CALCULATE(MAX('Table'[FH]),FILTER('Table','Table'[Product]=EARLIER('Table'[Product]) && 'Table'[FH] < EARLIER('Table'[FH])))
RETURN
IF(ISBLANK(_prevVal), 0, _prevVal)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Highlighted
Super User IV
Super User IV

Re: Subtracting rows based on another column category

@Zabeer , Try like a new column

Expected = [FH] - maxx(filter(table,[Product] = earlier([Product]) && [FH] < earlier([FH])),[FH])

 

Ideally, there should date to do this



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
My Recent Blog -Week is not so Weak Connect on Linkedin

Proud to be a Super User!

Highlighted
Community Champion
Community Champion

Re: Subtracting rows based on another column category

@Zabeer 

 

Try this

 

Output = 
var _CurrentProduct=NewTable[Product]
var _PreviousFH= MAXX(FILTER(NewTable,NewTable[FH]<EARLIER(NewTable[FH]) && NewTable[Product]=_CurrentProduct),NewTable[FH])
var _result=NewTable[FH]-_PreviousFH
return IF(ISBLANK(_PreviousFH),0,_result)

 

Capture.JPG



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂

View solution in original post

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Community Summit Australia – Join Online!

Community Summit Australia – Join Online!

Be a part of the leading Microsoft Business Applications digital event, curated for the APAC community.

Top Solution Authors
Top Kudoed Authors