Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

subtract two columns by group of third column

suppose I have the following table 

 

idgroupval1
1A2
2A3
3A4
4B4
5B6
6B2

 

How would I get the following result?

idgroupval1diff
1A20
2A31
3A41
4B40
5B62
6B2-4

 

Explanation of new column diff:

1. It is the difference between the current row and previous row of column val1

2. Whenever a new group starts in Group column the difference resets to 0

 

Essestially, the problem is how to subtract current value from it's previous value in a column by group (based on some third column)?

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Try a new column like

 

new column =
var _max = maxx(filter(table, [group] = earlier([group]) && [ID] < earlier([ID])),[ID])
return
val1 - maxx(filter(table, [group] = earlier([group]) && [ID] = _max),[val1])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@Anonymous , Try a new column like

 

new column =
var _max = maxx(filter(table, [group] = earlier([group]) && [ID] < earlier([ID])),[ID])
return
val1 - maxx(filter(table, [group] = earlier([group]) && [ID] = _max),[val1])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors