Forum Discussion
Last Non zero Value based on max date
Hi All
I am trying to get the last charged amount to an id which im running into the issue of getting zeros where the last entry is a zero.
My current formula only looks at the max value based on the latest date, the part im struggling with is if the returned value is zero i would like the last non zero amount.
example data of the issue,
| UnitId | ChargeAmount | StartDate |
| 78268 | 84.25 | 01/06/2006 00:42 |
| 78268 | 87.7 | 02/04/2007 00:00 |
| 78268 | 91.56 | 07/04/2008 00:00 |
| 78268 | 96.6 | 06/04/2009 00:00 |
| 78268 | 94.99 | 05/04/2010 00:00 |
| 78268 | 97.83 | 04/04/2011 00:00 |
| 78268 | 101.8 | 02/04/2012 00:00 |
| 78268 | 104.77 | 01/04/2013 00:00 |
| 78268 | 108.64 | 07/04/2014 00:00 |
| 78268 | 108.64 | 14/07/2014 00:00 |
| 78268 | 0 | 18/05/2015 17:42 |
Any help would be great.
Kind Regards
- Anonymous6 years ago
Anonymous Please try below measure.
Measure = VAR _maxdate = CALCULATE(MAX('Table'[StartDate]),FILTER(ALLEXCEPT('Table','Table'[UnitId]),'Table'[ChargeAmount]>0)) RETURN CALCULATE(MAX('Table'[ChargeAmount]),'Table'[StartDate]=_maxdate)If it helps accept as solution.
10 Replies
- AnonymousNot applicable
Anonymous Please try below measure.
Measure = VAR _maxdate = CALCULATE(MAX('Table'[StartDate]),FILTER(ALLEXCEPT('Table','Table'[UnitId]),'Table'[ChargeAmount]>0)) RETURN CALCULATE(MAX('Table'[ChargeAmount]),'Table'[StartDate]=_maxdate)If it helps accept as solution.
- AnonymousNot applicable
Hi Anonymous
I have tried to use your solution but it doesnt seem to present any values.
Measure =VAR _maxdate = CALCULATE(MAX(RentUnitCharge[StartDate]),FILTER(ALLEXCEPT(RentUnitCharge,'RentUnitCharge'[UnitId]),RentUnitCharge[ChargeAmount]>0))RETURN CALCULATE(MAX(RentUnitCharge[ChargeAmount]),RentUnitCharge[StartDate]=_maxdate)Have i done this correctly?Kidn Regards- AnonymousNot applicable
Try all instead of allexcept in filter section.
Thanks & regards,
Pravin Wattamwar.
If it resolves your problem mark it as solution and give kudos.