Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Getting averages from events

I'm really new to Power BI and would appreciate any assist in this. The warehouse I work in would like to have a visual report that shows the average pallet drop off time. All the information is recorded in three events; MPICK, TOPOF, and MDOFF. The UDC is the unique qualifier for every pallet. Is there a way to take the UDCs and average out the time taken? UDC_Pickup_Dropoff.jpg

5 REPLIES 5
Anonymous
Not applicable

I put in the code as you outlined it. It is showing an error saying the function Average cannot work with values of type String. Will the code need to be altered if the Date and Time Record columns are formats themselves? Originally the data table has a TIME column that combined the Date and Time. I created two columns DATE and TIME RECORD to have the data split.

DATE = 
FORMAT(Table[TIME].[Date] , "mm/dd/yyyy")

Time Format = 
FORMAT(Table[TIME] , "HH:MM:SS" )

UDC_Pickup_Dropoff.jpg 

Hi, @Anonymous 

 

Has your problem been solved, if so, please consider Accept a correct reply as the solution. If not, please provide your actual example data, please include a screenshot of the data format. What kind of expected results do you expect? You can also show it with pictures.

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thanks for looking into this. Ultimately I am trying to get an average time in seconds for the event TOPOF. In our warehouse, a UDC will be created with the MPICK event and record the time. The next timed event that is recorded for the UDC is the TOPOF. The last timed event is MDOFF. I have been able to get the average time it takes for every UDC with the following code:

 

Average Drop Off Time In Seconds = 
AVERAGEX (
    VALUES ( 'IN THE LAST'[UDC] ),
    CALCULATE (
        DATEDIFF ( MIN ( 'IN THE LAST'[TIME RECORD] ), MAX ( 'IN THE LAST'[TIME RECORD] ), SECOND )
    )
)

 

 The code I am attempting to use to get an average in seconds for the TOPOF event is this:

 

Average Top Off Time in Seconds = 
TIMEVALUE (
    FORMAT (
        CALCULATE (
            AVERAGE ( 'IN THE LAST'[TIME RECORD] ),
            FILTER ( 'IN THE LAST', [EVENT] = EARLIER ( 'IN THE LAST'[EVENT] ) )
        ),
        "hh:mm:ss"
    )
)

 

It is getting an error EARLIER/EARLIEST refers to an earlier row context which doesn't exist. I'm including a picture of the table I imported from our SQL database along with the formats and measures I'm currently using.

 

DATE = 
FORMAT('In The Last'[TIME].[Date] , "mm/dd/yyyy")
Time Format = 
FORMAT('In The Last'[TIME] , "HH:MM:SS" )
Total UDCs Cancelled = 
COUNTROWS( 
    (FILTER('IN THE LAST', 'IN THE LAST'[EVENT] = "MCANC")))
Total UDCs Worked = 
CALCULATE(
    DISTINCTCOUNT('IN THE LAST'[UDC]))

I'm actually an IT guy and my company thinks that because I'm IT I know how to program in DAX. Appreciate all the help.

 

 

DATE = 
FORMAT('In The Last'[TIME].[Date] , "mm/dd/yyyy")

Time Format = 
FORMAT('In The Last'[TIME] , "HH:MM:SS" )

Total UDCs Cancelled = 
COUNTROWS( 
    (FILTER('IN THE LAST', 'IN THE LAST'[EVENT] = "MCANC")))

Total UDCs Worked = 
CALCULATE(
    DISTINCTCOUNT('IN THE LAST'[UDC]))

 

Here is the picture of the table.
UDC_Pickup_Dropoff.jpg

v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

You can try the following methods.

Column:

Aver = 
TIMEVALUE (
    FORMAT (
        CALCULATE (
            AVERAGE ( 'Table'[TIME RECORD] ),
            FILTER ( 'Table', [EVENT] = EARLIER ( 'Table'[EVENT] ) )
        ),
        "hh:nn:ss"
    )
)

vzhangti_0-1655186629847.png

This is the average calculated for the different events, is it the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

PriyasonP
Regular Visitor

Hi,

 

When importing the table, ensure that the datatype of the Time Record Column is set as Duration.

 

The default visual level average may not work for duration type in source, so dax should help. Below is the DAX formula that I tried. I have also attached a sample power bi file with the calculation done. 

 
Average_Time_Record =
FORMAT(
          AVERAGE('Dataset'[Time Record]),
                           "HH:MM:SS")

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.