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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Daxtothemax
Helper I
Helper I

Calculating Task Progression

Looking for a way in Power BI to calculate the difference between values in the same column. Need the day over day change to the remaining duration. I have a formula that works but an issue has come up when durations are actually increased.  I would prefer to not show negative change and the change be based off the original duration only. Please see existing formula and example data below. 

 

Daxtothemax_0-1652212804283.png

 

 

 

Daxtothemax_1-1652212804403.png

 

 

 

 

 

 

Any help is greatly appreciated!

1 ACCEPTED SOLUTION

Hi @Daxtothemax 

 

Ahhh my bad!  Have amended by adding another VAR __t3 in the calculated column which basically says to get the value where the Task had the most recent value that was not a 0, etc., and it gives the results you're after:

 

 

Diff = 

VAR __t = FILTER ( 'Table' , 'Table'[Task] = EARLIER ( 'Table'[Task] ) && 'Table'[Date] < EARLIER ( 'Table'[Date] ) )
VAR __t1 =
    IF ( 
        ISEMPTY ( __t ) , 0 , 
            MAXX ( 
                TOPN ( 1 , __t , 'Table'[Date] , ) , 
                    'Table'[Remaining Duration (Hours)] ) - 'Table'[Remaining Duration (Hours)] 
                )
VAR __t2 = 

SWITCH ( 
    TRUE () ,
        __t1 > 0 , __t1 ,
        __t1 < 0 , 0 ,
        'Table'[Remaining Duration (Hours)] = 0 , MAXX ( FILTER ( ALL ( 'Table' ) , 'Table'[Task] = 'Table'[Task] && 'Table'[Date] <= EARLIER ('Table'[date] ) - 1 ) , __t1 ) ,
        'Table'[Change] )

VAR __t3 = 

SWITCH (
    TRUE () ,
        'Table'[Remaining Duration (Hours)] = 0 && __t2 > 0 , CALCULATE ( MIN ('Table'[Remaining Duration (Hours)] ) , FILTER ( 'Table' , 'Table'[Task] = EARLIER ('Table'[Task] ) && 'Table'[Remaining Duration (Hours)] > 0 ) ) , __t2 )

RETURN

__t3

The output is per below:

TheoC_0-1652306589489.png

And a copy of the new PBIX is attached 🙂

 

All the best mate!

Theo 

 

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

View solution in original post

7 REPLIES 7
TheoC
Super User
Super User

@Daxtothemax 

 

If you wanted the below to work within your existing column (removing the need for 2 columns), just adjust your calculated column to the following:

 

Diff = 

VAR __t = FILTER ( 'Table' , 'Table'[Task] = EARLIER ( 'Table'[Task] ) && 'Table'[Date] < EARLIER ( 'Table'[Date] ) )
VAR __t1 =
IF (
ISEMPTY ( __t ) , 0 ,
MAXX ( TOPN ( 1 , __t , 'Table'[Date] , ) ,
'Table'[Remaining Duration (Hours)] ) - 'Table'[Remaining Duration (Hours)] )
VAR __t2 =
SWITCH (
TRUE () ,
__t1 > 0 , __t1 ,
__t1 < 0 , 0 ,
'Table'[Remaining Duration (Hours)] = 0 , MAXX ( FILTER ( ALL ( 'Table' ) , 'Table'[Task] = 'Table'[Task] && 'Table'[Date] <= EARLIER ('Table'[date] ) - 1 ) , __t1 ) , 'Table'[Change] )

RETURN

__t2
TheoC_0-1652326829520.png

 

 

I've added the PBIX for the above to this post.

 

Hope this helps 

TheoC_1-1652326829523.png

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Ashish_Mathur
Super User
Super User

Hi,

These 2 calculated column formulas work

Calculated Column 1 = if(LOOKUPVALUE(Data[Remaining Duration (Hours)],Data[Date],CALCULATE(MAX(Data[Date]),FILTER(Data,Data[Task]=EARLIER(Data[Task])&&Data[Date]<EARLIER(Data[Date]))),Data[Task],Data[Task])<Data[Remaining Duration (Hours)],LOOKUPVALUE(Data[Remaining Duration (Hours)],Data[Date],CALCULATE(min(Data[Date]),FILTER(Data,Data[Task]=EARLIER(Data[Task])&&Data[Date]<EARLIER(Data[Date]))),Data[Task],Data[Task])-Data[Remaining Duration (Hours)],LOOKUPVALUE(Data[Remaining Duration (Hours)],Data[Date],CALCULATE(max(Data[Date]),FILTER(Data,Data[Task]=EARLIER(Data[Task])&&Data[Date]<EARLIER(Data[Date]))),Data[Task],Data[Task])-Data[Remaining Duration (Hours)])
Calculated Column 2 = MAX(0,Data[Calculated Column 1])

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Daxtothemax 

 

If you wanted the below to work within your existing column (removing the need for 2 columns), just adjust your calculated column to the following:

 

Diff = 

VAR __t = FILTER ( 'Table' , 'Table'[Task] = EARLIER ( 'Table'[Task] ) && 'Table'[Date] < EARLIER ( 'Table'[Date] ) )
VAR __t1 =
IF (
ISEMPTY ( __t ) , 0 ,
MAXX ( TOPN ( 1 , __t , 'Table'[Date] , ) ,
'Table'[Remaining Duration (Hours)] ) - 'Table'[Remaining Duration (Hours)] )
VAR __t2 =
SWITCH (
TRUE () ,
__t1 > 0 , __t1 ,
__t1 < 0 , 0 ,
'Table'[Remaining Duration (Hours)] = 0 , MAXX ( FILTER ( ALL ( 'Table' ) , 'Table'[Task] = 'Table'[Task] && 'Table'[Date] <= EARLIER ('Table'[date] ) - 1 ) , __t1 ) , 'Table'[Change] )

RETURN

__t2
TheoC_0-1652326829520.png

 

 

I've added the PBIX for the above to this post.

 

Hope this helps 

TheoC_1-1652326829523.png

 

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

TheoC
Super User
Super User

@Daxtothemax 

 

If you wanted the below to work within your existing column (removing the need for 2 columns), just adjust your calculated column to the following:

 

Diff = 

VAR __t = FILTER ( 'Table' , 'Table'[Task] = EARLIER ( 'Table'[Task] ) && 'Table'[Date] < EARLIER ( 'Table'[Date] ) )
VAR __t1 =
IF (
ISEMPTY ( __t ) , 0 ,
MAXX ( TOPN ( 1 , __t , 'Table'[Date] , ) ,
'Table'[Remaining Duration (Hours)] ) - 'Table'[Remaining Duration (Hours)] )
VAR __t2 =
SWITCH (
TRUE () ,
__t1 > 0 , __t1 ,
__t1 < 0 , 0 ,
'Table'[Remaining Duration (Hours)] = 0 , MAXX ( FILTER ( ALL ( 'Table' ) , 'Table'[Task] = 'Table'[Task] && 'Table'[Date] <= EARLIER ('Table'[date] ) - 1 ) , __t1 ) , 'Table'[Change] )

RETURN

__t2
TheoC_1-1652225871977.png

 

I've added the PBIX for the above to this post.

 

Hope this helps 🙂

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Hi @TheoC ,

 

Thank you for this, it's getting closer.  Still having an issue, Task A on 4/6 should equal 8 based on the original duration.  Any ideas on this?  Thank you again for the help!

Daxtothemax_0-1652276135443.png

 


 

Hi @Daxtothemax 

 

Ahhh my bad!  Have amended by adding another VAR __t3 in the calculated column which basically says to get the value where the Task had the most recent value that was not a 0, etc., and it gives the results you're after:

 

 

Diff = 

VAR __t = FILTER ( 'Table' , 'Table'[Task] = EARLIER ( 'Table'[Task] ) && 'Table'[Date] < EARLIER ( 'Table'[Date] ) )
VAR __t1 =
    IF ( 
        ISEMPTY ( __t ) , 0 , 
            MAXX ( 
                TOPN ( 1 , __t , 'Table'[Date] , ) , 
                    'Table'[Remaining Duration (Hours)] ) - 'Table'[Remaining Duration (Hours)] 
                )
VAR __t2 = 

SWITCH ( 
    TRUE () ,
        __t1 > 0 , __t1 ,
        __t1 < 0 , 0 ,
        'Table'[Remaining Duration (Hours)] = 0 , MAXX ( FILTER ( ALL ( 'Table' ) , 'Table'[Task] = 'Table'[Task] && 'Table'[Date] <= EARLIER ('Table'[date] ) - 1 ) , __t1 ) ,
        'Table'[Change] )

VAR __t3 = 

SWITCH (
    TRUE () ,
        'Table'[Remaining Duration (Hours)] = 0 && __t2 > 0 , CALCULATE ( MIN ('Table'[Remaining Duration (Hours)] ) , FILTER ( 'Table' , 'Table'[Task] = EARLIER ('Table'[Task] ) && 'Table'[Remaining Duration (Hours)] > 0 ) ) , __t2 )

RETURN

__t3

The output is per below:

TheoC_0-1652306589489.png

And a copy of the new PBIX is attached 🙂

 

All the best mate!

Theo 

 

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

TheoC
Super User
Super User

Hi   

You can achieve what you want by adding another Calculated Column like the below. A PBIX file is also attached to further assist if required.

 

Diff 2 = 

VAR _1 =
SWITCH (
TRUE () ,
'Table'[Diff] > 0 , 'Table'[Diff] ,
'Table'[Diff] < 0 , 0 ,
'Table'[Remaining Duration (Hours)] = 0 , MAXX ( FILTER ( ALL ( 'Table' ) , 'Table'[Task] = 'Table'[Task] && 'Table'[Date] <= EARLIER ('Table'[date] ) - 1 ) , 'Table'[Diff] ) ,
'Table'[Change] )

RETURN

_1

 

TheoC_0-1652225334314.png

Hope this helps!

Theo 🙂

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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