Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
Hi - I'm relatively new to DAX, and I have the following issue that I cannot get passed.
I have a table with invoices, and an related table (they share InvoiceID) with all ledger postings related to these invoices.
I want to create a custom column in the Invoice table with payment days (using DAX) based on the following rationale:
Hopeful someone can help.
/LarsM
Invoice and Postings table extract.
Invoice table extract
Postings table extract
[Payment Days] = // calc column
VAR __maxAmount =
MAXX(
RELATEDTABLE( Postings ),
Postings[Amount]
)
var __minAmount =
MINX(
RELATEDTABLE( Postings ),
Postings[Amount]
)
var __amountsAreCorrect =
__maxAmount > 0
&& ( __maxAmount + __minAmount = 0 )
var __dayOfMaxAmount =
CALCULATE(
VALUES( Postings[Date] ),
Postings[Amount] = __maxAmount
)
var __dayOfMinAmount =
CALCULATE(
VALUES( Postings[Date] ),
Postings[Amount] = __minAmount
)
var __onlyOnePairOfDatesFound =
COUNTROWS( __dayOfMinAmount ) = 1
&&
1 = COUNTROWS( __dayOfMaxAmount )
var __shouldCalculate =
__amountsAreCorrect && __onlyOnePairOfDatesFound
RETURN
if( __shouldCalculate, int(__dayOfMaxAmount - __dayOfMinAmount) )
This should cover all the problems you might have in the Postings table. For instance, there could not be a matching negative amount.. and the likes.
Best
D
Hi @larsm11
Try this
Column =
VAR __amounts =
CALCULATETABLE(
{
MIN( Postings[Amount] ),
MIN( Postings[Amount] )
}
)
RETURN
CALCULATE(
DATEDIFF( MIN( Postings[Date] ), MAX( Postings[Date] ), DAY ),
TREATAS( __amounts, Postings[Amount] )
)
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
7 | |
5 | |
4 | |
3 |
User | Count |
---|---|
12 | |
11 | |
10 | |
9 | |
8 |