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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

Calculate days paid too late

Hello everyone, I have a question regarding time calculations

 

I have invoice data with Issue date & Last payment date. Time clients get to pay is standard 1 month. Here is some sample data:

SampleData.png

 

The columns "Paid?" // "OnTime?" // "DaysLate" are calculated columns, the last one is the one I am having problems with.

 

Paid? = IF(FactHarvest_Invoices[Last Payment Date]<FactHarvest_Invoices[Issue Date],"NO","YES")
OnTime? = IF(FactHarvest_Invoices[Last Payment Date]>DATE(YEAR(FactHarvest_Invoices[Issue Date]),MONTH(FactHarvest_Invoices[Issue Date])+1,,DAY(FactHarvest_Invoices[Issue Date])),"YES","NO")
 
Now what I would like to do is in the DaysLate column is see the numbers of days that clients paid too late so 
DaysLate = FactHarvest_Invoices[Last Payment Date] - FactHarvest_Invoices[Last Payment Date] - 1 month
The problem is that I than get a date data type whiel I want an actuel number
 
Any ideas?
1 ACCEPTED SOLUTION
edhans
Super User
Super User

Use the DATEDIFF() function to return an integer.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

DaysLate = datediff(FactHarvest_Invoices[Last Payment Date] , FactHarvest_Invoices[Last Payment Date] , Day)-1

or

DaysLate = datediff(FactHarvest_Invoices[Last Payment Date] , FactHarvest_Invoices[Last Payment Date] , Month)

or

DaysLate = datediff(FactHarvest_Invoices[Last Payment Date] , FactHarvest_Invoices[Last Payment Date] , Day)

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
edhans
Super User
Super User

Use the DATEDIFF() function to return an integer.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Anonymous
Not applicable

Hi @edhans that seemed to work, any idea how can substract the 1 month payment time tho?

 

Last Payment date - Issue Date = just the difference between the dates. But I want to know how many days have passed the 1 month payment date, if that makes any sense?

Well, how would you do it in Excel? For example, if the first date is Jan 1 and the 2nd is Mar 15, that is 74 days. How would you add/subtract a month from that? Assume 30 days? You cannot really add a month to an integer as month have 28-31 days. For example, I've always worked with days when dealing with AR agings, not months.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Anonymous
Not applicable

I fixed it like this!
 
DaysLate = DATEDIFF(FactHarvest_Invoices[Last Payment Date], DATE(YEAR(FactHarvest_Invoices[Issue Date]),MONTH(FactHarvest_Invoices[Issue Date])+1,,DAY(FactHarvest_Invoices[Issue Date])) , DAY)

Excellent @Anonymous - glad you figured out a solution that works!



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

October NL Carousel

Fabric Community Update - October 2024

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