cancel
Showing results 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

## 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):

 Document Rut Date Capital Dif. Capital 123456 12345678 07-12-2022 2419 0 987654 55555555 24-11-2021 1000 0 990111 98765432 21-01-2019 6508,97 0 990111 98765432 29-05-2019 6697 188,03 990111 98765432 11-12-2019 6634 -63 990111 98765432 13-05-2020 7290 656 990111 98765432 03-12-2020 7258 -32 990111 98765432 26-05-2021 7356 98 990111 98765432 05-11-2021 8866 1510 990111 98765432 01-12-2021 8795 -71 990111 98765432 04-03-2022 8759 -36 990111 98765432 27-04-2022 9345 586 990111 98765432 05-07-2022 9588 243 990111 98765432 06-02-2023 10136 548

Greetings and thank you very much

2 REPLIES 2
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!

Announcements

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

#### Power BI Monthly Update - February 2024

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

#### Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

#### Microsoft Fabric Partner Community

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

Top Solution Authors
Top Kudoed Authors