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
RemiAnthonise
Helper V
Helper V

Measure for calculating 'new leave balance'

Hi guys,

 

I couldn't find the right answer to my problem in other topics so I need your help.

Below you see my current situation and my desired situation. What we have is:

- Total leave. This is a calculated column and it exists of 2 fields, together they make the total leave. Further you see leave taken, total leave taken (for this year, a running measure) and the new balance. 

 

What I want is:

The 'total leave' on the new line has to be the 'new balance' from the previous line, so A minus B. I know it's really easy and I've done it before but I don't get it working. 

For now, I try it this way so I don't have to share my dataset because it has confidential data.

leave balance.jpg

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

hi, @RemiAnthonise

After my test, you may try to this way as below:

Step1:

Add a group rank column for each Name by ProjectDate

group rank = RANKX(FILTER(Table1,Table1[Name]=EARLIER(Table1[Name])),Table1[ProjectDate],,ASC)

Step2:

Use this formula to add a new calculate column

new total leave = Table1[Total leave]-CALCULATE(SUM(Table1[Leave taken]),FILTER(Table1,Table1[Name]=EARLIER(Table1[Name])&&Table1[group rank]<EARLIER(Table1[group rank])))

or use this formula to add a new calculate measure

Measure = CALCULATE(SUM(Table1[Total leave]))-CALCULATE(SUM(Table1[Leave taken]),FILTER(ALLEXCEPT(Table1,Table1[Name]),Table1[group rank]<MAX(Table1[group rank])))

Result:

7.JPG

 

here is pbix, please try it.

https://www.dropbox.com/s/goqo9ig2v9swixg/Measure%20for%20calculating%20%27new%20leave%20balance%27....

 

 

Best Regards,

Lin

 

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-lili6-msft
Community Support
Community Support

hi, @RemiAnthonise

After my test, you may try to this way as below:

Step1:

Add a group rank column for each Name by ProjectDate

group rank = RANKX(FILTER(Table1,Table1[Name]=EARLIER(Table1[Name])),Table1[ProjectDate],,ASC)

Step2:

Use this formula to add a new calculate column

new total leave = Table1[Total leave]-CALCULATE(SUM(Table1[Leave taken]),FILTER(Table1,Table1[Name]=EARLIER(Table1[Name])&&Table1[group rank]<EARLIER(Table1[group rank])))

or use this formula to add a new calculate measure

Measure = CALCULATE(SUM(Table1[Total leave]))-CALCULATE(SUM(Table1[Leave taken]),FILTER(ALLEXCEPT(Table1,Table1[Name]),Table1[group rank]<MAX(Table1[group rank])))

Result:

7.JPG

 

here is pbix, please try it.

https://www.dropbox.com/s/goqo9ig2v9swixg/Measure%20for%20calculating%20%27new%20leave%20balance%27....

 

 

Best Regards,

Lin

 

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

You need to use EARLIER to find the previous row and grab the New Balance from it. See my article on Mean Time Before 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.