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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Datagulf
Responsive Resident
Responsive Resident

Create table to show if client had a successful transaction in the same month after payment failed

I have the following table.

Cust_ID Date transaction status Month 
1 01/01/2023 FAIL Jan  
1 02/01/2023 SUCCESS Jan  
2 02/01/2023 FAIL Jan  
3 02/01/2023 SUCCESS Jan  
4 03/01/2023 FAIL Jan  
1 01/02/2023 FAIL Feb 
1 02/02/2023 SUCCESS Feb 
 01/02/2023 FAIL Feb 
3 02/02/2023 SUCCESS Feb 
4 01/02/2023 FAIL Feb 
4 02/02/2023 SUCCESS Feb 
5 02/02/2023 SUCCESS Feb 

 

I want to create a table that is as follows.(Expected output)

Cust_ID MonthSuccessful Transaction
1 JanYes
2 JanNo
4 JanNo
1 FebNo
2 FebNo
4 FebYes

 

NB. 

All 1-time successful transactions for each client are not required in the output. 

For the months of January and February, we only have three transactions each in the output because they are either successful after a second trial or they failed completely.

 

 

All I am trying is to check if a client had a successful transaction in the same month after payment failed the first time. This is to decide if churn was decided by the number of failed transactions. How do I achieve that table? 

Thanks. 

1 ACCEPTED SOLUTION
barritown
Super User
Super User

Hi @Datagulf

I am not sure it is the optimal solution to your problem, but it should work. Please try the [DAX] code below with your real data.

BTW, the test case seems to be not quite correct: with Cust_ID = 1 and Month = "Feb" you should have "yes" in the table.

barritown_0-1688548267993.png

In plain text:

Table = 
FILTER ( 
    ADDCOLUMNS ( 
        SUMMARIZE ( data, [Cust_ID], [Month] ),
        "Successful Transaction",
        VAR CurrentMonth = [Month]
        VAR CurrentID = [Cust_ID]
        VAR FailExists = IF ( COUNTROWS ( FILTER ( data, [Cust_ID] = CurrentID && [Month] = CurrentMonth && [transaction status] = "FAIL" ) ) = 0, 0, 1 )
        VAR MinFail = MINX ( FILTER ( data, [Cust_ID] = CurrentID && [Month] = CurrentMonth && [transaction status] = "FAIL" ), [Date] )
        VAR MaxSuccess = MAXX ( FILTER ( data, [Cust_ID] = CurrentID && [Month] = CurrentMonth && [transaction status] = "SUCCESS" ), [Date] )
        RETURN SWITCH ( TRUE(),
            FailExists = 0, BLANK(),
            MaxSuccess > MinFail, "Yes",
            "No" ) ), 
NOT ISBLANK ( [Successful Transaction] ) )

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

View solution in original post

1 REPLY 1
barritown
Super User
Super User

Hi @Datagulf

I am not sure it is the optimal solution to your problem, but it should work. Please try the [DAX] code below with your real data.

BTW, the test case seems to be not quite correct: with Cust_ID = 1 and Month = "Feb" you should have "yes" in the table.

barritown_0-1688548267993.png

In plain text:

Table = 
FILTER ( 
    ADDCOLUMNS ( 
        SUMMARIZE ( data, [Cust_ID], [Month] ),
        "Successful Transaction",
        VAR CurrentMonth = [Month]
        VAR CurrentID = [Cust_ID]
        VAR FailExists = IF ( COUNTROWS ( FILTER ( data, [Cust_ID] = CurrentID && [Month] = CurrentMonth && [transaction status] = "FAIL" ) ) = 0, 0, 1 )
        VAR MinFail = MINX ( FILTER ( data, [Cust_ID] = CurrentID && [Month] = CurrentMonth && [transaction status] = "FAIL" ), [Date] )
        VAR MaxSuccess = MAXX ( FILTER ( data, [Cust_ID] = CurrentID && [Month] = CurrentMonth && [transaction status] = "SUCCESS" ), [Date] )
        RETURN SWITCH ( TRUE(),
            FailExists = 0, BLANK(),
            MaxSuccess > MinFail, "Yes",
            "No" ) ), 
NOT ISBLANK ( [Successful Transaction] ) )

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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