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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Need Help

Hi all, 

I need help to write a measure comparing two date fields ('GL post date' and 'Original Invoice Date') in same table (Sales Fact). I had written following code to calculate date difference with SUMX and MAXX as well, but its giving an error. I can only create measures as I have limited access to PowerBI desktop and not allowed to create column or table. Could you please let me know, if is it possible to calculate date difference for each row with this limited access? If yes, what do I need to change in following formula? 

 

AGE= AVERAGEX('Sales Fact', DATEDIFF('Sales Fact'[GL Post Date], 'Sales Fact'[Original Invoice Date], DAY))
4 REPLIES 4
Sahir_Maharaj
Super User
Super User

Note that this measure will only give you the total date difference for all the rows in the 'Sales Fact' table. If you want to see the date difference for each individual row, you'll need to create a pivot table or matrix visualization and place the measure in the values section of the visualization.


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
➤ The Tech Journal Blog: https://sahirmaharaj.tech
➤ About: https://sahirmaharaj.com/about.html
➤ Email: [email protected]
➤ 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
Sahir_Maharaj
Super User
Super User

This measure uses the SUMX function to sum the date differences for each row in the 'Sales Fact' table. The VALUES function is used to extract the unique values for the 'Row' column in the 'Sales Fact' table.


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
➤ The Tech Journal Blog: https://sahirmaharaj.tech
➤ About: https://sahirmaharaj.com/about.html
➤ Email: [email protected]
➤ 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
Sahir_Maharaj
Super User
Super User

Here's an alternate approach that you can use to calculate the date difference for each row in the 'Sales Fact' table:

 

AGE = 
VAR DateDiff = DATEDIFF('Sales Fact'[GL Post Date], 'Sales Fact'[Original Invoice Date], DAY)
RETURN SUMX(VALUES('Sales Fact'[Row]), DateDiff)

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
➤ The Tech Journal Blog: https://sahirmaharaj.tech
➤ About: https://sahirmaharaj.com/about.html
➤ Email: [email protected]
➤ 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
Sahir_Maharaj
Super User
Super User

Hello @Anonymous,

 

The formula you provided will return an average of the date difference between 'GL Post Date' and 'Original Invoice Date' for all the rows in the 'Sales Fact' table.

 


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
➤ The Tech Journal Blog: https://sahirmaharaj.tech
➤ About: https://sahirmaharaj.com/about.html
➤ Email: [email protected]
➤ 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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.