Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

putting time intervals into bins

Hi Everyone I have been struggling with a task for quite a while now without getting anywhere. I hope You can help me.  I have unixtime and datetime to work with.   I have a table of customers th...
  • v-lili6-msft's avatar
    6 years ago

    hi Anonymous 

    For your case, you could try this way as below:

    Step1:

    You must define a bin date time dim table, you could refer to this formula:

    DateTime bins Table = 
    SELECTCOLUMNS( 
        GENERATE (
            CALENDAR ( MIN ( data[starttime] ), MAX ( data[endtime] ) ),
            GENERATESERIES (
                TIME ( 00, 0, 0 ),  --From
                TIME ( 23, 59, 0 ), --To
                TIME ( 0, 1, 0 )    --Every 1 mins
            )
        ),
        "Datetime", [Date]+[Value],"Date",[Date],"Time",[Value]
    )

    Step2:

    Use this formula get the result measure

    Measure = 
    CALCULATE (
        COUNTA ( data[Customer no] ),
        FILTER (
            data,
            data[starttime] <= SELECTEDVALUE ( 'DateTime bins Table'[Datetime] )
                && SELECTEDVALUE ( 'DateTime bins Table'[Datetime] ) <= data[endtime]
        )
    )

     

    Here is sample pbix file, please try it.

     

    and here is a similar post, you could refer to it.

     

    Regards,

    Lin