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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
analyst123
Frequent Visitor

Calculating Average from a measure

Hello,

I have a dataset where I am trying to find the average of a measure to show it as a card on my dashboard. 

I have used the following measure code to get the time duration between two dates: 

 

DOWNTIME (MINUTES) = SUMX('Source', CALCULATE(
DATEDIFF(MIN(Source[APPEARED]), MIN(Source[DISAPPEARED]), MINUTE) +
(SECOND(MIN(Source[DISAPPEARED])) - SECOND(MIN(Source[APPEARED]))) / 60
))
 
I need to calculate the average of this duration based on the count of 'message text'. 
I tried using the following formula:
 
Measure = AVERAGEX(VALUES(Source[MESSAGE NUMBER]), CALCULATE(
DATEDIFF(MIN(Source[APPEARED]), MIN(Source[DISAPPEARED]), MINUTE) +
(SECOND(MIN(Source[DISAPPEARED])) - SECOND(MIN(Source[APPEARED]))) / 60))
 
But it does not give me the accurate value. 
 This is an example of the layout:
analyst123_1-1724941439582.png

 

Here, the average should be 38/23 = 1.65, but instead the average time is 1.25 minutes.

 

1 ACCEPTED SOLUTION
v-yohua-msft
Community Support
Community Support

Hi, @analyst123 

I create a sample table:

vyohuamsft_1-1725001807544.png

Then create a new measure and try the following DAX expression:

AverageDowntime = 
DIVIDE(
    SUMX(VALUES('Table'[Message number]), CALCULATE(
        DATEDIFF(MIN('Table'[APPEARED]), MIN('Table'[DISAPPEARED]), MINUTE) +
        (SECOND(MIN('Table'[DISAPPEARED])) - SECOND(MIN('Table'[APPEARED]))) / 60
    )),
    DISTINCTCOUNT('Table'[MESSAGE NUMBER])
)

 

Here is my preview:

vyohuamsft_2-1725001877424.png

 

How to Get Your Question Answered Quickly 

Best Regards

Yongkang Hua

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

View solution in original post

2 REPLIES 2
v-yohua-msft
Community Support
Community Support

Hi, @analyst123 

I create a sample table:

vyohuamsft_1-1725001807544.png

Then create a new measure and try the following DAX expression:

AverageDowntime = 
DIVIDE(
    SUMX(VALUES('Table'[Message number]), CALCULATE(
        DATEDIFF(MIN('Table'[APPEARED]), MIN('Table'[DISAPPEARED]), MINUTE) +
        (SECOND(MIN('Table'[DISAPPEARED])) - SECOND(MIN('Table'[APPEARED]))) / 60
    )),
    DISTINCTCOUNT('Table'[MESSAGE NUMBER])
)

 

Here is my preview:

vyohuamsft_2-1725001877424.png

 

How to Get Your Question Answered Quickly 

Best Regards

Yongkang Hua

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

bhanu_gautam
Super User
Super User

@analyst123 , Try below DAX

 

Average Downtime (Minutes) =
DIVIDE(
    SUMX(
        VALUES(Source[MESSAGE NUMBER]),
        CALCULATE(
            DATEDIFF(MIN(Source[APPEARED]), MIN(Source[DISAPPEARED]), MINUTE) +
            (SECOND(MIN(Source[DISAPPEARED])) - SECOND(MIN(Source[APPEARED]))) / 60
        )
    ),
    COUNTROWS(VALUES(Source[MESSAGE NUMBER]))
)



Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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