Forum Discussion
GregB49
5 years agoHelper I
Time representation with DATEDIFF
Hi all ! I'm stuck on this one for good. Here is my problem on PowerBI. I have a sensor, that sends to the DB its state "Marche"(On) or "Arrêt"(Off). When the state change, it sends a new row, wi...
- 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
GregB49
5 years agoHelper I
My bad 😅
So now, the formula is working, I've just changed the return for :
RETURN IF (StartDate = EndDate, 'TF GRA 700 (2)'[Heure de fin] - 'TF GRA 700 (2)'[Heure de début], firstDayDuration+NbFullDays*NbHoursPerDay+LastDayDuration) Maybe I'm wrong ?
Otherwise, it was not returning the right answer. Now I got this :
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.
And I have to say, I don't understand how it will "help me" to represent 24h on the 06/02/2021 ?
Thanks again,
Greg
Thanks again,
Greg
Anonymous
5 years agoNot applicable
If you need help with SUMMARIZE /want to learn it better check this post:
https://www.plainlyresults.com/blog/power-bi-dax-how-to-summarize-data-from-multiple-tables/