Forum Discussion
Total Value incorrect with measure
Hi All,
I have come across an issue where my Time Spent Column is showing an incorrect total, as you can see from the Time column there are some big numbers showing and the total should not equal to 11 hours it should be more. The Time spent times are correct for the ID numbers I just need to get the total amount correct
The measure I used to calculate the Time Spent is below.. Is someone able to advise me on how I can get the exact total amount to show?-
Thanks all
- Anonymous5 years ago
Hi Anonymous ,
I created the data and simulated your scenario:
Here are the steps you can follow:
You can consider Hour, Minutes, Seconds to use HASONEVALUE to total the total, and finally combine them together
1. Create measure.
Hour = var _hour =DATEDIFF(MAX('Table'[Date2]),MAX('Table'[Date1]),HOUR) VAR __table = SUMMARIZE('Table',[ID Numbers],"__value",_hour) RETURN IF(HASONEVALUE('Table'[ID Numbers]),_hour,SUMX(__table,[__value]))Minute = var _hour =DATEDIFF(MAX('Table'[Date2]),MAX('Table'[Date1]),HOUR) var _min=DATEDIFF(MAX('Table'[Date2]),MAX('Table'[Date1]),MINUTE)-_hour *60 VAR __table = SUMMARIZE('Table',[ID Numbers],"__value",_min) RETURN IF(HASONEVALUE('Table'[ID Numbers]),_min,SUMX(__table,[__value]))Seconds = var _hour =DATEDIFF(MAX('Table'[Date2]),MAX('Table'[Date1]),HOUR) var _min=DATEDIFF(MAX('Table'[Date2]),MAX('Table'[Date1]),MINUTE)-_hour *60 var _sec=DATEDIFF(MAX('Table'[Date2]),MAX('Table'[Date1]),SECOND) -_hour * 3600 - _min*60 VAR __table = SUMMARIZE('Table',[ID Numbers],"__value",_sec) RETURN IF(HASONEVALUE('Table'[ID Numbers]),_sec,SUMX(__table,[__value]))correct_time = [Hour]&" Hours "&[Minute]&" Minutes "&[Seconds]&" Seconds "&""2. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
2 Replies
- amitchandak
Super User
Anonymous ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.
also refer to these, if these can help
https://radacad.com/calculate-duration-in-days-hours-minutes-and-seconds-dynamically-in-power-bi-using-dax
https://social.technet.microsoft.com/wiki/contents/articles/33644.powerbi-aggregating-durationtime-in-dax.aspx - AnonymousNot applicable
Hi Anonymous ,
I created the data and simulated your scenario:
Here are the steps you can follow:
You can consider Hour, Minutes, Seconds to use HASONEVALUE to total the total, and finally combine them together
1. Create measure.
Hour = var _hour =DATEDIFF(MAX('Table'[Date2]),MAX('Table'[Date1]),HOUR) VAR __table = SUMMARIZE('Table',[ID Numbers],"__value",_hour) RETURN IF(HASONEVALUE('Table'[ID Numbers]),_hour,SUMX(__table,[__value]))Minute = var _hour =DATEDIFF(MAX('Table'[Date2]),MAX('Table'[Date1]),HOUR) var _min=DATEDIFF(MAX('Table'[Date2]),MAX('Table'[Date1]),MINUTE)-_hour *60 VAR __table = SUMMARIZE('Table',[ID Numbers],"__value",_min) RETURN IF(HASONEVALUE('Table'[ID Numbers]),_min,SUMX(__table,[__value]))Seconds = var _hour =DATEDIFF(MAX('Table'[Date2]),MAX('Table'[Date1]),HOUR) var _min=DATEDIFF(MAX('Table'[Date2]),MAX('Table'[Date1]),MINUTE)-_hour *60 var _sec=DATEDIFF(MAX('Table'[Date2]),MAX('Table'[Date1]),SECOND) -_hour * 3600 - _min*60 VAR __table = SUMMARIZE('Table',[ID Numbers],"__value",_sec) RETURN IF(HASONEVALUE('Table'[ID Numbers]),_sec,SUMX(__table,[__value]))correct_time = [Hour]&" Hours "&[Minute]&" Minutes "&[Seconds]&" Seconds "&""2. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly