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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

View solution in original post

3 REPLIES 3
v-yiruan-msft
Community Support
Community Support

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

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
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

Greg_Deckler
Super User
Super User

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...


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors