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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
DoubtfulGuest
Frequent Visitor

DAX caclulated column to find the next date in column based on criteria or condition

Hi All,

 

I've been searching online to find a solution. It looks easy enough in SQL using partitioning, but beyond me in DAX. I have the table below and would like to add a calculated column for Payment date.

 

For each Customer , whenever there is a row where Transaction Type = Missed, return the Date when the next row appears for that customer with Transaction Type = Payment. If there is no Payment, leave blank. If it's any other type of Transaction Type, leave blank.

 

So for row 3 where there is a Missed, 20 and 31/03/2021....I'd like to add a new column to return 09/04/2021 as this when the next future Payment was made (row 6).

 

Once I get the Missed Date and Payment Date on one row - I'll be be able to do a DATEDIFF to calculate the delay in Payment.

 

Many thanks in advance for any guidance.

 

CustomerTransaction TypeTransaction ValueDatePayment Date
0001Direct Debit2031/01/2021 
0001Direct Debit2028/01/2021 
0001Missed2031/03/2021 
0001Fee505/04/2021 
0001Misc107/04/2021 
0001Payment2009/04/2021 
0001Direct Debit2031/04/2021 
0001Missed2031/05/2021 
0001Misc702/06/2021 
0001Fee806/06/2021 
0001Payment2012/06/2021 
0001Adjustment914/06/2021 
0002Missed10031/03/2021 
0002Payment10015/04/2021 
0002Direct Debit10031/04/2021 
0002Missed10031/05/2021 
0002Adjustment-2903/06/2021 
0002Payment10027/06/2021 
0003Missed3915/03/2021 
0003Missed3915/04/2021 
1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Although you should consider doing you calculation as a measure, here is a column expression that seems to work.

 

Payment Date =
VAR thisdate = Payments[Date]
RETURN
IF(
Payments[Transaction Type] = "Missed",
CALCULATE(
MIN( Payments[Date] ),
Payments[Transaction Type] = "Payment",
Payments[Date] >= thisdate,
ALLEXCEPT( Payments, Payments[Customer] )
)
)

 

mahoneypat_0-1647994379834.png

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

5 REPLIES 5
CNENFRNL
Community Champion
Community Champion

Date Deferred = 
IF(
    PYMT[Transaction Type] = "Missed",
    VAR date_deferred =
        MINX(
            FILTER(
                PYMT,
                PYMT[Customer] = EARLIER( PYMT[Customer] )
                    && PYMT[Date] > EARLIER( PYMT[Date] )
                    && PYMT[Transaction Value] = EARLIER( PYMT[Transaction Value] )
                    && PYMT[Transaction Type] = "Payment"
            ),
            PYMT[Date]
        )
    RETURN
        IF( date_deferred > 0, date_deferred - PYMT[Date] )
)

CNENFRNL_0-1648011636129.png

 

Excel worksheet formula is powerful to solve such a simple question,

CNENFRNL_1-1648011733800.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!

@CNENFRNL- Thank you for your help. I really appreciate all the effort and depth you've gone to.

mahoneypat
Microsoft Employee
Microsoft Employee

Although you should consider doing you calculation as a measure, here is a column expression that seems to work.

 

Payment Date =
VAR thisdate = Payments[Date]
RETURN
IF(
Payments[Transaction Type] = "Missed",
CALCULATE(
MIN( Payments[Date] ),
Payments[Transaction Type] = "Payment",
Payments[Date] >= thisdate,
ALLEXCEPT( Payments, Payments[Customer] )
)
)

 

mahoneypat_0-1647994379834.png

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


@mahoneypat- Thank you so much for your help. Your solution suited me the most as it allows any first payment of any size to be allocated against the Missed...which is what I needed.

davehus
Memorable Member
Memorable Member

Hi @DoubtfulGuest , OK, so this is what I've come up with. There may be other ways but see below.

 

Here's the PBIX https://drive.google.com/file/d/1Pjg-lsaaeb_NpqUK7953vbuuqOAZQLis/view?usp=sharing

 

Start by creating a calculated table to filter to missed/payment - Test Table

Create ranking column to create an index

Offset calculation with give to the date to carry out your datediff.

Datediff for difference.

 

Hope this helps. Please accept my solution if it meets your needs.

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.