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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
adeptus2008
Frequent Visitor

Value difference between rows grouped by value

Hi there, 

 

I have a table like that:

account_idorders_idcdateexpdatemoney
218966107373222.05.201822.05.20195
281343109969430.11.201830.11.201915
326276112503230.01.201923.01.20208
218966128579808.01.202008.01.202135
326276129340323.01.202023.01.20214
281343129635229.01.202012.04.20219
218966129758330.01.202030.02.202010

I want to calculate money difference, between curent and previous rows within the group of unique account_id. Thanks for any ideas.

My desrired table with calculated column would be

account_idorders_idcdateexpdatemoneymoney_diff
218966107373222.05.201822.05.201950
281343109969430.11.201830.11.2019150
326276112503230.01.201923.01.202070
218966128579808.01.202008.01.20213530
326276129340323.01.202023.01.20214-3
281343129635229.01.202012.04.20219-6
218966129758330.01.202030.02.202010-25
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

Create new columns like

 new column last date= maxx(filter(table1,table1[account_id]=earlier(account_id) && table1[expdate]<earlier(table1[expdate]))table1[expdate]) 
 new column money_diff = table[money] -maxx(filter(table1,table1[account_id]=earlier(account_id) && table1[expdate]=earlier(table1[new column last date]))table1[money]) 

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Proud to be a Datanaut Connect on Linkedin

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

3 REPLIES 3
Anonymous
Not applicable

Hi @adeptus2008,

Whether you got your expected result by creating any measure or calculated column? If still not, you can try to create one calculated column as below:

money_diff =
if(COUNTROWS(filter('ATable','ATable'[account_id]=EARLIER('ATable'[account_id])&&'ATable'[orders_id]<EARLIER('ATable'[orders_id])))=0,
0,
'ATable'[money]- CALCULATE(max('ATable'[money]),filter('ATable','ATable'[account_id]=EARLIER('ATable'[account_id])&&'ATable'[orders_id]<EARLIER('ATable'[orders_id]))))

MONEY_DIFF.JPG

Best Regards

Rena

amitchandak
Super User
Super User

Create new columns like

 new column last date= maxx(filter(table1,table1[account_id]=earlier(account_id) && table1[expdate]<earlier(table1[expdate]))table1[expdate]) 
 new column money_diff = table[money] -maxx(filter(table1,table1[account_id]=earlier(account_id) && table1[expdate]=earlier(table1[new column last date]))table1[money]) 

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Proud to be a Datanaut Connect on Linkedin

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
Greg_Deckler
Community Champion
Community Champion

See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors