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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Mike282
Helper III
Helper III

Calculating Returned customers by customer and plan

Hi all,

 

So I've got a dilemma. I'm trying to calculate returned customers but for a specific plan rather than looking at the customer as a whole. So just a bit of background. Our product is a monthly renewal based subscription. Every customer has a ID, a subscription Plan and and renewal dates. As it's monthly you expect 1 row per month per plan. So a sample data would be:

 

 

Customer IDSubscription PlanRenewal DateQuantity
123Plan 11/01/20211
123Plan 21/01/20211
123Plan 11/02/20211
123Plan 21/02/20211
123Plan 11/03/20211
123Plan 21/03/20211
123Plan 11/04/20211
123Plan 21/04/20211
123Plan 11/05/20211
123Plan 21/05/20211
123Plan 11/06/20211
123Plan 21/06/20211
123Plan 11/07/20211
123Plan 21/07/20211
123Plan 11/08/20211
123Plan 21/08/20211
123Plan 11/09/20211
123Plan 11/10/20211
123Plan 11/11/20211
123Plan 21/11/20211
123Plan 11/12/20211
123Plan 21/12/20211

 

Note this is the subscription of only one customer as noted by the fact they all have the same customer ID. They've subscribed to 2 types of plans. Both plans are monthly as noted by the monthly payments. Note that for the customer with their plan 2 subscription, they lapsed payment in September and then returned in November.

 

I'm trying to calculate the returned value of 1 for that customer for a specific plan at the specific date from which they returned for that plan. In the case of this example it's for Plan 2 and a returned value of 1 on the 1st of November 2021 as they lapsed payment in September 2021.

 

Any help would be greatly appreciated. It's doing my head in lol.

 

Kind regards,

Mike 

1 ACCEPTED SOLUTION
sreenathv
Solution Sage
Solution Sage

As usual, there are many ways. But I am giving you a DAX code which you will understand what is happening in each step.

sreenathv_0-1638877029956.png

 

ReturnCount = 
VAR CurrentCustomer = Subsriptions[Customer ID]
VAR CurrentPlan = Subsriptions[Subscription Plan]
VAR CurrentRenewalDate = Subsriptions[Renewal Date]
VAR FilteredTable = FILTER(
                Subsriptions,
                Subsriptions[Customer ID]=CurrentCustomer &&
                Subsriptions[Subscription Plan] = CurrentPlan &&
                Subsriptions[Renewal Date] < CurrentRenewalDate
            )
VAR PreviousRenewalDate = 
        MAXX(
            FilteredTable
            ,Subsriptions[Renewal Date]
            )
        
VAR Difference = 
    IF(
        isempty(FilteredTable),
        0,
        CurrentRenewalDate-PreviousRenewalDate
    )
RETURN IF(Difference>31,1,0)

 

 

In this example, The table name is "Subscriptions"

View solution in original post

1 REPLY 1
sreenathv
Solution Sage
Solution Sage

As usual, there are many ways. But I am giving you a DAX code which you will understand what is happening in each step.

sreenathv_0-1638877029956.png

 

ReturnCount = 
VAR CurrentCustomer = Subsriptions[Customer ID]
VAR CurrentPlan = Subsriptions[Subscription Plan]
VAR CurrentRenewalDate = Subsriptions[Renewal Date]
VAR FilteredTable = FILTER(
                Subsriptions,
                Subsriptions[Customer ID]=CurrentCustomer &&
                Subsriptions[Subscription Plan] = CurrentPlan &&
                Subsriptions[Renewal Date] < CurrentRenewalDate
            )
VAR PreviousRenewalDate = 
        MAXX(
            FilteredTable
            ,Subsriptions[Renewal Date]
            )
        
VAR Difference = 
    IF(
        isempty(FilteredTable),
        0,
        CurrentRenewalDate-PreviousRenewalDate
    )
RETURN IF(Difference>31,1,0)

 

 

In this example, The table name is "Subscriptions"

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.