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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
apatwal
Helper III
Helper III

Transaction Gaps

Hey,

 

I need help in creating below DAX.

We need to calculate the transaction gap between all transactions for each customer. The maximum transactions gap is the longest a customer has gone between transactions.

For this I have written below DAX, but the problem here is I am not able to find max and average value as its getting sum up.

Also, transaction Gap should exculde weekends.

apatwal_1-1651580561604.png

 

Transaction Gap = 
var current_date = SELECTEDVALUE(data[Invoice Date])
var previous_invoice_date = 
CALCULATE(
    MAX(data[Invoice Date]),
    FILTER(
        ALLEXCEPT(data,data[Customer Name],data[Product]),
        data[Invoice Date] < current_date
    )
)

var diff = 
CALCULATE(
    COUNTROWS('Date'),
    DATESBETWEEN('Date'[Date],previous_invoice_date,current_date),
    'Date'[IsWeekend] = FALSE(),
    ALL(data)
)

RETURN diff
1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1651584374682.png

 

For fun only, Excel worksheet formulas are powerful enough,

CNENFRNL_1-1651584455154.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1651584374682.png

 

For fun only, Excel worksheet formulas are powerful enough,

CNENFRNL_1-1651584455154.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

johnt75
Super User
Super User

You could create a measure like

Max gap = 
var summaryTable = ADDCOLUMNS( SUMMARIZE( 'data', 'data'[Customer Name], 'data'[Product]),
"@val", [Transaction Gap])
return MAXX( summaryTable, [@val])

You can do the same with AVERAGEX

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.