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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
mandini210
New Member

Calculate the number of days between earliest and latest dates in a group

I have searched the forums with *almost* success but the DAX I've found isn't helping. I have a project table in which I'm trying to calculate the length of the overal project (Project Name). In this example, the total project duration would be the datediff of 6/11/2018 - 5/4/2023, or 1788 days.  Thanks in advance for any assistance!!

LineIDProject NameCategorySubcategoryActual StartActual/Forecasted FinishCurrent Duration
500Project ADesignROW6/11/201811/9/2018151
501Project ADesignROW10/12/201810/16/2019369
502Project ADesignPlanning1/31/201912/4/2019307
503Project ADesignEnvironmental11/19/20182/28/2020466
504Project ADesignEnvironmental1/23/20198/31/2020586
505Project ADesignEnvironmental1/18/20195/28/2020496
506Project ADesignEnvironmental4/24/20191/8/2020259
507Project ADesignEnvironmental2/21/20205/20/202089
508Project ADesignROW7/15/201912/2/2020506
509Project ADesignEnvironmental11/21/201911/16/2020361
510Project ADesignEnvironmental12/4/201911/17/2020349
512Project ADesignFinal Design12/31/20195/18/2020139
513Project ADesignFinal Design11/18/20196/15/2020210
514Project ADesignEnvironmental10/28/201910/7/2020345
515Project ADesignFinal Design12/26/20199/29/2020278
516Project ADesignFinal Design5/29/20209/16/2020110
517Project ADesignFinal Design9/17/20201/8/2021113
518Project ADesignProcurement1/8/20215/6/2021118
519Project AConstructionConstruction5/6/20215/4/2023728
1 ACCEPTED SOLUTION

there is a difference between a table, and a table visual.  The former has your data, the latter is a Power BI User interface element.

 

lbendlin_0-1598659453326.png

 

On the right is a table. On the left are visuals, and the highlighted one is a table visual.

View solution in original post

8 REPLIES 8
lbendlin
Super User
Super User

There are many ways that can be done. One would be via SUMMARIZE(), another one via ALLEXCEPT() etc.  What have you tried so far?

I've tried the calculate (https://community.powerbi.com/t5/Desktop/getting-the-max-and-min-date-of-a-group/td-p/680844); i've tried the allexcept (https://community.powerbi.com/t5/Desktop/Help-With-finding-the-earliest-Date/td-p/146353); i've tried https://community.powerbi.com/t5/Desktop/Using-earliest-and-latest-dates/td-p/574672. 

 

I've tried so many they've all blurred together! I feel like maybe I'm conflating a few different ones at this point.

Here's a very simple example. Put your Project Name in a table visual and then add this measure

 

 

Max Duration = CALCULATE(datediff(min('Duration'[Actual Start]),max('Duration'[Actual/Forecasted Finish]),DAY))

 

 

(I added a Project B with a different end date to show the difference)

 

lbendlin_0-1598654602741.png

 

Your output is exactly what I want! When I used your code with my table name, I get "The expression specified in the query is not a valid table expression."

 

Can you explain what you mean by putting my project name into a table visual?

 

Thank you so much for your help!

"When I used your code with my table name, I get "The expression specified in the query is not a valid table expression.""

 

Please elaborate. I don't understand what you are doing.

 

In your pbix file go to the UI section, place a table visual onto the canvas, add the "Project Name" column to the visual.

Am I understanding you to say that I have to have two tables? My original table that I pasted a section of in my original post, and another table of project names?

there is a difference between a table, and a table visual.  The former has your data, the latter is a Power BI User interface element.

 

lbendlin_0-1598659453326.png

 

On the right is a table. On the left are visuals, and the highlighted one is a table visual.

I have never been so thankful for smart computer people in my LIFE!! You are amazing and moved to the top of the "gold star for being awesome" list.

 

My disconnect was thinking it was a column, not a measure. This works perfectly!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.