Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi All,
I need to calculate invoice payment days. I managed to do it with a simple DAX formula below and place measure in a table, so that it correctly shows difference in days per document:
Solved! Go to Solution.
// Obiviously, the field Paid Document No in
// Purchase Payments must be hidden. Slicing
// should always be done via dimensions, never
// fact tables with the sole exception of
// degenerate dimensions. If you stick to this,
// the measure should always work correctly.
Payment days =
AVERAGEX(
DISTINCT( 'Purchase Invoices'[Document No] ),
CALCULATE(
var MaxPaymentDate =
MAX( 'Purchase Payments'[Payment Date] )
var DocumentDate =
selectedvalue( 'Purchase Invoices'[Document Date] )
var DateDiff_ =
datediff(
DocumentDate,
coalesce( MaxPaymentDate, UTCTODAY() ),
DAY
)
return
DateDiff_
)
)
// Obiviously, the field Paid Document No in
// Purchase Payments must be hidden. Slicing
// should always be done via dimensions, never
// fact tables with the sole exception of
// degenerate dimensions. If you stick to this,
// the measure should always work correctly.
Payment days =
AVERAGEX(
DISTINCT( 'Purchase Invoices'[Document No] ),
CALCULATE(
var MaxPaymentDate =
MAX( 'Purchase Payments'[Payment Date] )
var DocumentDate =
selectedvalue( 'Purchase Invoices'[Document Date] )
var DateDiff_ =
datediff(
DocumentDate,
coalesce( MaxPaymentDate, UTCTODAY() ),
DAY
)
return
DateDiff_
)
)
Apologies for late reply; I was on sick leave.
That is actually working. Love the Coalesce formula 🙂
The only thing that is missing is Day in DateDiff formula, but that was easy fix 😉
Thanks a lot!
Hi there. Yeah... I've fixed it. Sometimes I forget to fill in some details because about 95% of all the formulas I write on the forums I do without any model before my eyes and therefore have no means of testing. A quick test would immediately tell me "DAY" was missing. Glad it works for you.
@Daniel_G , You need have common document table and then try like
averageX(values(document[document]), IF(ISBLANK(MAX('Purchase Payments'[PaymentDate])),DATEDIFF(MIN('Purchase Invoices'[DocumentDate]),UTCTODAY(),DAY),DATEDIFF(MIN('Purchase Invoices'[DocumentDate]),MAX('Purchase Payments'[PaymentDate]),DAY)))
Thanks, I now know that AverageX was the answer. I think that @Anonymous's solution is better, as it does not require creating a 'middle man' table.
Still appreciate your help!
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
24 | |
9 | |
7 | |
6 | |
6 |
User | Count |
---|---|
29 | |
11 | |
11 | |
10 | |
6 |