Forum Discussion

GregB49's avatar
GregB49
Helper I
5 years ago
Solved

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...
  • AilleryO's avatar
    AilleryO
    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 TabDates

     

    Then 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