Forum Discussion

OneHotEncoder's avatar
OneHotEncoder
Frequent Visitor
3 years ago

Build average value of 30 min time interval

Dear community,

 

I have the following table existing of a column with time stamps (data type: Time, format hh:mm:ss) and the counted amount of sold goods (whole numbers). Example table:

 

 

Time Stamp             Sold Goods

18:25:50                         1

07:21:05                         3

11:45:35                         2

....                                   ...

 

I now want to create a query which calculates the average amount of sold goods per 30 min interval.

Output would then be:

 

Time interval            Average amount of sold goods

07:00 - 07:30                                  5

07:30 - 08:00                                  3

08:00 - 08:30                                  2

...                                                    ....

 

I tried with the following DAX code which should solve the problem:

 

Averageby30min =
    VAR TimeIntervals =
        GENERATE(
            SUMMARIZE('TableName', 'TableName'[Time Stamp]),
            SELECTCOLUMNS(
                SUMMARIZE('TableName', 'TableName'[Time Stamp]),
                "@StartTime", TIME(HOUR('TableName'[Time Stamp]), FLOOR(MINUTE('TableName'[Time Stamp]) / 30) * 30, 0),
                "@EndTime", TIME(HOUR('TableName'[Time Stamp]), FLOOR(MINUTE('TableName'[Time Stamp]) / 30 + 1) * 30, 0)
            )
        )
    RETURN
        AVERAGEX(
            SUMMARIZE(TimeIntervals, [@StartTime], [@EndTime]),
            CALCULATE(
                SUM('TableName'[Time Stamp]),
                'TableName'[ime Stamp] >= [@StartTime] && 'Query1'[book_substring] < [@EndTime]
            )
        )

 

 

Im always getting the following error code:

Too few arguments were passed to the FLOOR function. The minimum argument count for the function is 2.

 

Has anyone already solved this issue or know the error?

 

Thank you very much.

 

 

 

 

 

 

1 Reply

  • As the documentation to FLOOR states you must indicate what you want to round to.  In your case should be 1.
     
    Usually these kinds of calendars should be created further upstream, in Power Query or in an external calendar table.