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
Anonymous
Not applicable

Finding date for last non zero value in a table

I'm looking to build a measure that returns the last date where an hour is forecast.  I have to have 0's in the forecast for a burndown chart measure I'm using otherwise I get odd spikes.

 

Currently using 

Burndown = A_F_COMBINED_DATA[ForecastTotal]-calculate(sum(A_F_COMBINED_DATA[Hours]),FILTER(ALL(A_F_COMBINED_DATA[Date]),A_F_COMBINED_DATA[Date] <= Max (A_F_COMBINED_DATA[Date])))
 
ForecastTotal = calculate(SUM(A_F_COMBINED_DATA[Hours]),ALL(A_F_COMBINED_DATA[Hours],A_F_COMBINED_DATA[Date]))

 

I then use this:

 

ForecastMaxDate = Max(A_F_COMBINED_DATA[Date])
 
But will get the last date in the whole data set as 0 is read as a positive.
 
What I'm looking for is the last non-zero value and return the date associated with it.

 

So for the below example, A would be 18/12/19

B would be 20/12/19.

 

Any ideas?

 

ItemDateHours
A18/12/191
B18/12/190
A19/12/190
B19/12/192
A20/12/190
B20/12/191
A23/12/190
B23/12/190

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Please try the measure below and see if the result achieve your expectation.

Measure = 
var a = CALCULATE(MAX('Table'[Date]),FILTER(ALLEXCEPT('Table','Table'[Item]),'Table'[Hours]<>0))
return
IF(MAX('Table'[Date])=a,MAX('Table'[Hours]),BLANK())

Result would be shown as below.

1.PNG 

 

Best Regards,

Jay

Community Support Team _ Jay Wang

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

4 REPLIES 4
Anonymous
Not applicable

Hi @Anonymous ,

 

Please try the measure below and see if the result achieve your expectation.

Measure = 
var a = CALCULATE(MAX('Table'[Date]),FILTER(ALLEXCEPT('Table','Table'[Item]),'Table'[Hours]<>0))
return
IF(MAX('Table'[Date])=a,MAX('Table'[Hours]),BLANK())

Result would be shown as below.

1.PNG 

 

Best Regards,

Jay

Community Support Team _ Jay Wang

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

parry2k
Super User
Super User

@Anonymous add following measure to get the date

 

First Date = 
CALCULATE( 
FIRSTDATE ( hurs[Date] ),
KEEPFILTERS( hurs[Hours] = 0 ) 
)

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Thanks Parry2k - First date records the first 0 in the list, I'm after the item before the last 0 in the data set,

 

This seems to work though, so I'm pretty sure you put me on the right track!

 

CALCULATE(LASTDATE(BUDGET_DATA[Date]),KEEPFILTERS((BUDGET_DATA[Hours]<>0)))
 

Hi @Anonymous ,
I think your original max function should work with an added filter context. Try this as a calculated column:

CALCULATE(MAX([Date]), FILTER(BUDGET_DATA, [Item] = EARLIER([Item]) && [Hours] <> 0))

 



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

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.