Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

How To Create Measures Over Hours

Hello ,

 

I have read through many of the other messages, but I can't seem to get this one to work.

I have sensor data (Please, find it posted) and want to create two measures over 24 hours:

1-) The first measure is a rolling a verage of sensor values over 24 hours 

2-) The second measure is a count of the sensor values 24 hours rolling average which exceeded 4. That is, I want to count only those sensor values of the newly created measure that exceeded 4. If there is no exceedance, it should return 0. 

 

Thank you 


Date /Time          Sensor Values 

01.01.2021 00:000,38
01.01.2021 01:000,30
01.01.2021 02:000,30
01.01.2021 03:000,31
01.01.2021 04:000,31
01.01.2021 05:000,32
01.01.2021 06:000,32
01.01.2021 07:000,31
01.01.2021 08:000,31
01.01.2021 09:000,31
01.01.2021 10:000,30
01.01.2021 11:000,31
01.01.2021 12:000,31
01.01.2021 13:000,32
01.01.2021 14:000,33
01.01.2021 15:000,33
01.01.2021 16:000,34
01.01.2021 17:000,33
01.01.2021 18:000,33
01.01.2021 19:000,34
01.01.2021 20:000,35
01.01.2021 21:000,35
01.01.2021 22:000,34
01.01.2021 23:000,34
02.01.2021 00:000,34
02.01.2021 01:000,33
02.01.2021 02:000,33
02.01.2021 03:000,32
02.01.2021 04:000,32
02.01.2021 05:000,32
02.01.2021 06:000,33
02.01.2021 07:000,34
02.01.2021 08:000,34
02.01.2021 09:000,34
02.01.2021 10:000,35
02.01.2021 11:000,35
02.01.2021 12:000,35
02.01.2021 13:000,35
02.01.2021 14:000,35
02.01.2021 15:000,37
02.01.2021 16:000,37
02.01.2021 17:000,37
02.01.2021 18:000,37
02.01.2021 19:000,35
02.01.2021 20:000,36
02.01.2021 21:000,36
02.01.2021 22:000,36
02.01.2021 23:000,35
03.01.2021 00:000,34
03.01.2021 01:000,35
03.01.2021 02:000,35
03.01.2021 03:000,35
03.01.2021 04:000,33
03.01.2021 05:000,32
03.01.2021 06:000,33
03.01.2021 07:000,33
03.01.2021 08:000,31
03.01.2021 09:000,30
03.01.2021 10:000,29
03.01.2021 11:000,30
03.01.2021 12:000,29
03.01.2021 13:000,29
03.01.2021 14:000,29
03.01.2021 15:000,30
03.01.2021 16:000,29
03.01.2021 17:000,30
03.01.2021 18:000,29
03.01.2021 19:000,29
03.01.2021 20:000,29
03.01.2021 21:000,29
03.01.2021 22:000,28
03.01.2021 23:000,28
04.01.2021 00:000,28
04.01.2021 01:000,27
04.01.2021 02:000,26
04.01.2021 03:000,27
04.01.2021 04:000,27
04.01.2021 05:000,29
04.01.2021 06:000,30
04.01.2021 07:000,31
04.01.2021 08:000,32
04.01.2021 09:000,32
04.01.2021 10:000,32
04.01.2021 11:000,33
04.01.2021 12:000,32
04.01.2021 13:000,33
04.01.2021 14:000,43
04.01.2021 15:000,34
04.01.2021 16:000,34
04.01.2021 17:000,32
04.01.2021 18:000,31
04.01.2021 19:000,31
04.01.2021 20:000,28
04.01.2021 21:000,29
04.01.2021 22:000,29
04.01.2021 23:000,29
05.01.2021 00:000,51
05.01.2021 01:000,28
05.01.2021 02:000,29
05.01.2021 03:000,29
05.01.2021 04:000,30
05.01.2021 05:000,30
05.01.2021 06:000,31
05.01.2021 07:000,31
05.01.2021 08:000,32
05.01.2021 09:000,32
05.01.2021 10:000,31
05.01.2021 11:000,31
05.01.2021 12:000,31
05.01.2021 13:000,30
05.01.2021 14:000,30
05.01.2021 15:000,33
05.01.2021 16:000,32
05.01.2021 17:000,33
05.01.2021 18:000,33
05.01.2021 19:000,33
05.01.2021 20:000,32
05.01.2021 21:000,32
05.01.2021 22:000,32
05.01.2021 23:000,30
  • Hi Anonymous 
    Here is your file updated based on 34hr averages only at end of each day https://www.dropbox.com/t/XvUdc0zpksXlL9t8
    Your report looks like this

    Once you start having values that generate averages above 4 then "Blank" card will start showing numbers.
    Please let me know if you are now fully satisfied. Thank you.

9 Replies

  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi Engineer Anonymous 
    Here is the sample file with solution https://www.dropbox.com/t/Wuw3IVn7ofWHqEr5
    Dealing with time in dax is not optimum therefore I recommend that you start with adding an index column to your table. It will cost you one click in power query

    The code for the two measures is:

     

     

     

    Moving Average 24hrs = 
    VAR CurrentIndex =
        MIN (Data[Index] )
    VAR ShiftedIndex =
        CurrentIndex - 24
    VAR MovingAverage =
        CALCULATE (
            AVERAGE ( Data[Sensor Values] ),
            REMOVEFILTERS ( Data[Date/Time] ),
            Data[Index] >= ShiftedIndex,
            Data[Index] <= CurrentIndex
        )
    VAR Result =
        IF ( 
            CurrentIndex >= 24,
            MovingAverage
        )
    RETURN
        Result
    Above 34 = 
    VAR FilterTable =
        FILTER ( 
            VALUES ( Data[Index] ),
            [Moving Average 24hrs] > 34
        )
    VAR Result =
        COUNTROWS ( FilterTable )
    RETURN
        Result

     

     

     

    And this is how thw report looks like

    If this answers your query, I kindly request you to mark this reply as acceptable solution. Have agreat day!

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello tamerj1 ,

      Thank you very much! The first measure is fine.However, and before marking it as an acceptable solution, the second measure needs to count only specific rows; those values that match 24 moving averages. Please see the photo for illustration. Thank you very much and looking forward to your reply!

       

       

       

      • tamerj1's avatar
        tamerj1
        Community Champion

        Hi Anonymous 
        Refer to updated file https://www.dropbox.com/t/6BJyRDp0745ewhPL
        You need to create a new date (date only) column:

         

        Date = DATE ( YEAR ( Data[Date/Time] ), MONTH ( Data[Date/Time] ), DAY ( Data[Date/Time] ) )

         

        The report looks like this

        Please let me know if this what you need.

    • Anonymous's avatar
      Anonymous
      Not applicable

      TOK  Thank you for your suggestion. I need these measures in DAX because I want to use them in paginated reports!