Forum Discussion
rnehrboss
4 years agoHelper II
Creating a last maximum? calculation
I'd like to create a measure that looks through last records finds the local max (100 in this example) and then uses the time and battery level from that record, along with the most recent local min ...
rnehrboss
4 years agoHelper II
Anyone able to help?
Let me know if I didn't explain it well.
Thanks!
Anonymous
4 years agoNot applicable
Hi rnehrboss ,
You can try this code to achieve your goal.
Measure =
VAR _LastDatetime_100 = CALCULATE(MAX('Table'[create_time]),FILTER('Table','Table'[Battery] = 100))
VAR _LatestDate = CALCULATE(MAX('Table'[create_time]))
VAR _LatestDate_Battery = CALCULATE(MIN('Table'[Battery]),FILTER('Table','Table'[create_time] = _LatestDate))
VAR _Battery_Diff = 100-_LatestDate_Battery
VAR _DateDiff = DATEDIFF(_LastDatetime_100,_LatestDate,MINUTE)
VAR _Hour = QUOTIENT(_DateDiff,60)
VAR _Minutes = MOD(_DateDiff,60)
RETURN
COMBINEVALUES(" ",_Battery_Diff,"% used in",_Hour,"Hours and",_Minutes,"Minutes")
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- rnehrboss4 years agoHelper II
Thanks Rico,
It's a good solution if the battery is taken all the way to 100. But if not, it won't work. I'm really looking for the local maximum (meaning the last number where the number before and after are smaller). That way if charged to 90% it will still find that time and calculate correctly.
Thanks!