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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Cortana
Helper IV
Helper IV

How to calculate sum of duration for every stage filtered by ID [If missing show NOT AVAILABLE] ?

I have a table like this-

 whatIhave.jpg

Here, every opportunity starts from the stage named 6 Qualification and ends with the stage named 1 Closed Won. The current stage of an opportunity is the stage of the latest CreatedDate.

 

What I want is if I select any opportunity by filtering it should show the current stage name and how many days it is staying on that stage and also the history of the previous stages. and if there is no previous stage record it will show Not Available. For example Consider the first opportunityID - 0066g00000MPrRuAAL. It should show like this table-

6 Qualification     Not Available
5 Solution Fit      176 [58+0+11+8+34+56+9]

 

So is it possible? 

Sample data can be downloaded from here.

 

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

Hi, @Cortana ;
First you could create a table.

Stage = VALUES('data'[StageName])

You could create a measure as follow:

Measure = 
var _count=CALCULATE(SUM('data'[StageDays]),FILTER(ALL(data),[ID]=MAX('data'[ID])&& [StageName]=MAX('Stage'[StageName])))+0
var _maxstage=CALCULATE(LEFT(MIN('data'[StageName]),1),FILTER(ALL(data),[ID]=MAX('data'[ID])))
return IF(LEFT(MIN('Stage'[StageName]),1)>=_maxstage,IF(_count=0, "Not Available",_count))

The final show:

vyalanwumsft_0-1658735742557.png

Or 

Measure 2 = 
var _count=CALCULATE(SUM('data'[StageDays]),FILTER(ALL(data),[ID]=MAX('data'[ID])&& [StageName]=MAX('Stage'[StageName])))+0

return IF(_count=0, "Not Available",_count)

vyalanwumsft_1-1658735876902.png


Best Regards,
Community Support Team _ Yalan Wu
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

6 REPLIES 6
v-yalanwu-msft
Community Support
Community Support

Hi, @Cortana ;
First you could create a table.

Stage = VALUES('data'[StageName])

You could create a measure as follow:

Measure = 
var _count=CALCULATE(SUM('data'[StageDays]),FILTER(ALL(data),[ID]=MAX('data'[ID])&& [StageName]=MAX('Stage'[StageName])))+0
var _maxstage=CALCULATE(LEFT(MIN('data'[StageName]),1),FILTER(ALL(data),[ID]=MAX('data'[ID])))
return IF(LEFT(MIN('Stage'[StageName]),1)>=_maxstage,IF(_count=0, "Not Available",_count))

The final show:

vyalanwumsft_0-1658735742557.png

Or 

Measure 2 = 
var _count=CALCULATE(SUM('data'[StageDays]),FILTER(ALL(data),[ID]=MAX('data'[ID])&& [StageName]=MAX('Stage'[StageName])))+0

return IF(_count=0, "Not Available",_count)

vyalanwumsft_1-1658735876902.png


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

 

@v-yalanwu-msft 

Precious. thanks a lot.

lbendlin
Super User
Super User

You don't need any explicit measures for that, you get the implicit mesasures for free

 

lbendlin_0-1658456581820.png

 

@lbendlin Thank you so much. Is it possible to show "Not available" where there is a blank?

Why would you want to waste all that screen real estate?

I need to use that in another table. Thats why.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.