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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Glennboy
New Member

Rank recurring payment dates per order id (consecutive dates)

I have recurring payments, some of which succeed and some fail. Those which fail are attempted again the next day and then some of those will succeed and some will fail (up to 5 consecutive payment dates)

Data looks something like this:

Order idPay DateSuccess/Fail
12329/07/2024Fail
12330/07/2024Fail
12331/07/2024Fail
12301/08/2024Fail
12302/08/2024Success
12404/07/2024Fail
12405/07/2024Success
12404/08/2024Success
12503/07/2024Success
12503/08/2024Success
12605/07/2024Success

 

If there is not a payment date for the same order on the previous day then it should be ranked 1, consecutive payments to be ranked accordingly

What I want is this:

Order idPay DateSuccess/FailPay Sequence
12329/07/2024Fail1
12330/07/2024Fail2
12331/07/2024Fail3
12301/08/2024Fail4
12302/08/2024Success5
12404/07/2024Fail1
12405/07/2024Success2
12404/08/2024Success1
12503/07/2024Success1
12503/08/2024Success1
12605/07/2024Success

1

 

I feel like this shouldn't be too difficult but I just cannot get it right! 

Thanks

1 ACCEPTED SOLUTION
muhammad_786_1
Super User
Super User

Hi @Glennboy 

 

You can use this DAX formula to rank payments. It resets the rank to 1 if there is no payment date for the same order on the previous day, and increments the rank for consecutive payments accordingly:

 

Pay Sequence =
VAR CurrentOrder = 'Payments'[Order id]
VAR CurrentDate = 'Payments'[Pay Date]
VAR PreviousDate =
    CALCULATE(
        MAX('Payments'[Pay Date]),
        FILTER(
            'Payments',
            'Payments'[Order id] = CurrentOrder &&
            'Payments'[Pay Date] < CurrentDate
        )
    )
RETURN
    IF(
        DATEDIFF(PreviousDate, CurrentDate, DAY) = 1,
        CALCULATE(
            COUNTROWS('Payments'),
            FILTER(
                'Payments',
                'Payments'[Order id] = CurrentOrder &&
                'Payments'[Pay Date] <= CurrentDate
            )
        ),
        1
    )

 

muhammad_786_1_0-1725639959971.png

Please see, if this is what you want.

 

Best Regards,

 

Muhammad Yousaf

If this post helps, then please consider "Accept it as the solution" to help the other members find it more quickly.

 

LinkedIn

View solution in original post

2 REPLIES 2
glennwatts2002
New Member

Thanks so much for your response.

This is almost what I need, but I'm afraid that I failed to relay another scenario! 

These are recurring payments, so it's quite possible that they had multiple successful payments and then a failure.

When I apply the DAX code above I see the following: 

glennwatts2002_0-1727095771794.png

As you can see, the counter is cumulative and although the first payment attempt in June shown above has correctly reverted to 1, the next one is showing 5 (cumulative count), so I think there needs to be an extra clause to ensure that each sequence starts from scratch and increases by one for each attempt

muhammad_786_1
Super User
Super User

Hi @Glennboy 

 

You can use this DAX formula to rank payments. It resets the rank to 1 if there is no payment date for the same order on the previous day, and increments the rank for consecutive payments accordingly:

 

Pay Sequence =
VAR CurrentOrder = 'Payments'[Order id]
VAR CurrentDate = 'Payments'[Pay Date]
VAR PreviousDate =
    CALCULATE(
        MAX('Payments'[Pay Date]),
        FILTER(
            'Payments',
            'Payments'[Order id] = CurrentOrder &&
            'Payments'[Pay Date] < CurrentDate
        )
    )
RETURN
    IF(
        DATEDIFF(PreviousDate, CurrentDate, DAY) = 1,
        CALCULATE(
            COUNTROWS('Payments'),
            FILTER(
                'Payments',
                'Payments'[Order id] = CurrentOrder &&
                'Payments'[Pay Date] <= CurrentDate
            )
        ),
        1
    )

 

muhammad_786_1_0-1725639959971.png

Please see, if this is what you want.

 

Best Regards,

 

Muhammad Yousaf

If this post helps, then please consider "Accept it as the solution" to help the other members find it more quickly.

 

LinkedIn

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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