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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Charu
Post Patron
Post Patron

Difference between two columns and finding the Average it

Dear All,

 

Please help me to write the formula to find the difference between two date columns and then take the average of that.

 

Below is the sample

 

LAST_UPDATED_DATECREATION_DATEDAY DIFF 
10/4/2018 0:009/30/2018 0:004Average =1.428571429
10/1/2018 0:009/30/2018 0:001 
10/1/2018 0:009/30/2018 0:001 
10/1/2018 0:009/30/2018 0:001 
10/1/2018 0:009/30/2018 0:001 
10/1/2018 0:009/30/2018 0:001 
10/1/2018 0:009/30/2018 0:001 

 

Average to be shown in the CARD visual.

 

Thanks in advance

1 ACCEPTED SOLUTION

Hi @Greg_Deckler

 

Calculated Column for DATEDIFF is throwing an error saying "Function DATEDIFF is not allowed as part of calculated Column DAX expressions on DirectQuery models.

 

So I tried the DATEDIFF with Measure and it's accepting only with aggregate function like MIN,MAX etc,like below

1.DAY DIFF = DATEDIFF(MIN('Table1'[LAST_UPDATED_DATE]),MIN('Table1'[CREATION_DATE]),DAY)
 
2.AVG OF DAY = AVERAGEX('Table1','Table1'[DAY DIFF])
 
It's working fine.
 
Thank you so much for your timely support.

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

Well, you should be able to create a column:

 

DAY DIFF = DATEDIFF([LAST_UPDATED_DATE],[CREATION_DATE],DAY)

 

And then a measure:

 

Average of DAY DIFF = AVERAGEX('Table',[DAY DIFF])



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler

 

Calculated Column for DATEDIFF is throwing an error saying "Function DATEDIFF is not allowed as part of calculated Column DAX expressions on DirectQuery models.

 

So I tried the DATEDIFF with Measure and it's accepting only with aggregate function like MIN,MAX etc,like below

1.DAY DIFF = DATEDIFF(MIN('Table1'[LAST_UPDATED_DATE]),MIN('Table1'[CREATION_DATE]),DAY)
 
2.AVG OF DAY = AVERAGEX('Table1','Table1'[DAY DIFF])
 
It's working fine.
 
Thank you so much for your timely support.

Glad you got it sorted out. Yeah, DirectQuery causes some issues with certain DAX functions.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
AlB
Community Champion
Community Champion

Hi @Charu

 

Try this for your measure:

 

DiffAvg =
AVERAGEX ( Table1, Table1[ LAST_UPDATED_DATE] - Table1[CREATION_DATE] )

 

Hi @AlB

 

When I create the AverageX measure with two date fields received the below error message

ORA-00904:"t6"."CREATION_DATE":invalid identifier.The exception was raised by the IDbCommand interface

 

 

Helpful resources

Announcements
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.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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