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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Syndicate_Admin
Administrator
Administrator

Calculate difference between two capitals associated with a rut

Hello Community,

I need help calculating the difference between two rows (capital) associated with the SAME rut and document. Each row shows an amount of capital associated with a corresponding date.

Attached information on how I need it to be displayed (I need to get the column in bold):

DocumentRutDateCapitalDif. Capital
1234561234567807-12-202224190
9876545555555524-11-202110000
9901119876543221-01-20196508,970
9901119876543229-05-20196697188,03
9901119876543211-12-20196634-63
9901119876543213-05-20207290656
9901119876543203-12-20207258-32
9901119876543226-05-2021735698
9901119876543205-11-202188661510
9901119876543201-12-20218795-71
9901119876543204-03-20228759-36
9901119876543227-04-20229345586
9901119876543205-07-20229588243
9901119876543206-02-202310136548

Greetings and thank you very much

2 REPLIES 2
Greg_Deckler
Super User
Super User

@Syndicate_Admin 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....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Thank you very much for your help ... I was trying to do it according to your example and it works for me ... but how could this column calculated based on RUT and Document condition?

This code worked for me, but I need to condition it:

Variation =
VAR _Actual = Hoja1[Capital]
VAR _Previous = MAXX(FILTER(Hoja1,Hoja1[Capital] < _Actual),Hoja1[Capital])
return
(_Actual - _Previous)
Thank you very much dear!

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.