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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
stvn43
Frequent Visitor

AverageX with Calculated Column and Format function

I created a calculated column to get a time duration value using the Format function, and it looks great, but I can't use AverageX on it because now it's a string value. Is there a way to get this formatting w/out using the Format function to keep the output value to a time-based value?
Here is my DAX for the calculated column and the assoicated mesaure:
Difference =
VAR EditTime =
  IF([editbegintime] <= 0, "00:00:00",
    FORMAT(TimeToEdit[editendtime] - TimeToEdit[editbegintime],"HH:MM:SS"))
Return
EditTime
Time to Caption =
VAR TTC =  
    AVERAGEx(FILTER(TimeToEdit, [service] = "Captioning"), [Difference])
Return
TTC
 
2 ACCEPTED SOLUTIONS
Sahir_Maharaj
Super User
Super User

Hello @stvn43,

 

You can use the TIME function in DAX to create a duration value instead of using the FORMAT function.

 

Difference = 
VAR EditTime =
  IF([editbegintime] <= 0, TIME(0, 0, 0),
    TimeToEdit[editendtime] - TimeToEdit[editbegintime])
RETURN EditTime

Time to Caption =
VAR TTC = AVERAGEX(FILTER(TimeToEdit, [service] = "Captioning"), [Difference])
RETURN FORMAT(TTC, "HH:MM:SS")

 

By using the TIME function, you can now use the AverageX function on the Difference column because it returns a duration value instead of a string.

 

I hope this helps! Let me know if you have any further questions.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

View solution in original post

stvn43
Frequent Visitor

Many thanks, Sahir!

View solution in original post

2 REPLIES 2
stvn43
Frequent Visitor

Many thanks, Sahir!

Sahir_Maharaj
Super User
Super User

Hello @stvn43,

 

You can use the TIME function in DAX to create a duration value instead of using the FORMAT function.

 

Difference = 
VAR EditTime =
  IF([editbegintime] <= 0, TIME(0, 0, 0),
    TimeToEdit[editendtime] - TimeToEdit[editbegintime])
RETURN EditTime

Time to Caption =
VAR TTC = AVERAGEX(FILTER(TimeToEdit, [service] = "Captioning"), [Difference])
RETURN FORMAT(TTC, "HH:MM:SS")

 

By using the TIME function, you can now use the AverageX function on the Difference column because it returns a duration value instead of a string.

 

I hope this helps! Let me know if you have any further questions.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors
Top Kudoed Authors