Forum Discussion
Time representation with DATEDIFF
- 5 years ago
With this you get all dates required ?
Tables des Dates Intervalles = VAR DateDebut=MIN('TF GRA 700 (2)'[Date de début]) VAR DateFin=MAX('TF GRA 700 (2)'[Date de début]) VAR TabDates=SELECTCOLUMNS(CALCULATETABLE(Dates, DATESBETWEEN(Dates[Date],DateDebut,DateFin)), "Dates TF",Dates[Date]) RETURN TabDatesThen you need to add column(s), but depends on what you want.
If you want the total hours per day or make difference by machine...Next step could be something inspired by that :
Tables des Dates Intervalles = VAR DateDebut=MIN('TF GRA 700 (2)'[Date de début]) VAR DateFin=MAX('TF GRA 700 (2)'[Date de début]) VAR TabDates=SELECTCOLUMNS(CALCULATETABLE(Dates, DATESBETWEEN(Dates[Date],DateDebut,DateFin)), "Dates TF",Dates[Date]) VAR TabDates2=CROSSJOIN(TabDates,'TF GRA 700 (2)') VAR TabDates3=ADDCOLUMNS(TabDates2,"Valeur",IF([Dates TF]>='TF GRA 700 (2)'[Date de début]&&[Dates TF]<='TF GRA 700 (2)'[Date de fin],1,0)) RETURN FILTER(TabDates3,[Valeur]=1)This could be done with less lines but at least it is step by step.
You should have a table with that with all dates and a column to select only dates you are interested in.
Hope this helps
My bad 😅
So now, the formula is working, I've just changed the return for :
Also I had to change TIME(24,0,0) to TIME(23,59,59) otherwise it was returning 00:00-Start date and not 24:00 - Start date. Maybe there is a better way ?
On the 05/02/2021, at 14:42:13, it return 2h35m, what apparently is not good because it should be : FirstDayDuration +NbFullDay*NbHoursPerDay+LastDayDuration =
(24-14h42) + 1*24h + 17h17 = 50h34m (approximatively)
So I guess it returns 2h35 because it's 50h35-24h-24h. That means, it goes back to 00h every time it goes to 24h.
Thanks again,
Greg
Hi,
You're right, PBI doesn't propose a time format for duration that goes over 24h. But it's quite easy to format it if needed. In your case I don't think so, but otherwise you could use :
//This measure is formatting a time in H M S
VAR HoursCalc=TRUNC(SUM(TabXXX[TotalTime]),0)//Take the whole number part for hours
VAR MinutesCalc=ROUND((SUM(TabXXX[TotalTime])-HoursCalc)*60,0)//Remain is minutes
VAR HourseCalc2=IF(LEN(HourCalc)=1,"0"&HeureCalc,HeureCalc)//Add prefix 0 to H
VAR MinutesCalc2=IF(LEN(MinutesCalc)=1,"0"&MinutesCalc,MinutesCalc)//Add prefix 0 to mn
RETURN
IF(ISBLANK(HoursCalc2),BLANK(),HoursCalc2 & " h ") & IF(ISBLANK(MinutesCalc2),BLANK(),MinutesCalc2 & " mn")In your case I think you need to create a table dynamically to store your values, with something like this :
CALCULATETABLE(DateTable,
DATESBETWEEN(DateTable[Date],StartDate,EndDate)This should create a Date Table with the values you need, and to add to it your column with your calculated time, have a look at :
This should do the trick.
Let us know...
- GregB495 years ago
Helper I
I'm not sure to understand...
I think here are the limits of my comprehension 🤔I stripped my pbix of any sensitive data, and uploaded it :
https://we.tl/t-9EYU25IIeBCould you develop a bit more your idea of the dynamic table and the link your make with the hours per day ?
Thank you !- GregB495 years ago
Helper I
Okay with Plainly information, it did something like that :
Var myTable = CALCULATETABLE( SUMMARIZE('TF GRA 700 (2)','TF GRA 700 (2)'[Date de début],"Heures par jour", SUM('TF GRA 700 (2)'[Jour passé])), DATESBETWEEN(Dates[Date],MIN('TF GRA 700 (2)'[Date de début]),MAX('TF GRA 700 (2)'[Date de fin])), 'TF GRA 700 (2)'[Etat]="Marche" ) Return myTableWhat returns me :
I think the error is from my formula, because I still don't have the missing days...
But it seems we are getting closer, but I don't know in what direction to go...- AilleryO5 years ago
Memorable Member
Hi,
Your SUMMARIZE function, groups by Date Début.
If you remove it, do you have all required dates ?
Maybe all dates are the same range for any log ?
I'll have a look at the pbix file you sent...