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
APR92
Frequent Visitor

Detect Past Month lost customer

Hi,

I'm trying to find the customers that I lost from the previous month.

So far I've been able to calculate it individually but I'm stuck with the subtotals.

 

The model is a single table inndicating if a customer is active or not. The expected outcome is the measure "Lost".

 

APR92_0-1697523806819.png

 

The measure for past months looks like this (works fine):

Past Month =:
VAR var1 =
    CALCULATE(
        SUM(Consulta1[Active]),
        PREVIOUSMONTH(Consulta1[Date])
    )

RETURN
    var1

The measure for lost looks like this (the subtotals don't work fine): 

Lost =
    VAR var1 = SUM(Consulta1[Active]) - [Past Month]

    RETURN
    IF(
        var1>=0,
        BLANK(),
        var1
    )
 
Any idea? Thanks!!
1 ACCEPTED SOLUTION

Hey @APR92, there is probably a much cleaner way to do this, but try this:

Lost2 = 
VAR selectedDate =
    SELECTEDVALUE(Consulta1[Date])
VAR selectedCategory =
    SELECTEDVALUE(Consulta1[Category])
VAR tbl =
    ADDCOLUMNS (
        ADDCOLUMNS (
            Consulta1,
            "Active Last Month",
                MAXX (
                    FILTER (
                        ALL ( Consulta1 ),
                        Consulta1[Date] < EARLIER(Consulta1[Date])
                            && (
                                Consulta1[Category] = EARLIER(Consulta1[Category])
                                    || ISBLANK ( EARLIER(Consulta1[Category]) )
                            )
                    ),
                    Consulta1[Active]
                )
        ),
        "Lost",
            SWITCH (
                TRUE,
                ISBLANK ( [Active Last Month] ), BLANK (),
                [Active Last Month] < Consulta1[Active], 0,
                [Active Last Month] - Consulta1[Active]
            )
    )
VAR lost = 
    SUMX (
        FILTER (
            tbl,
            Consulta1[Date] = selectedDate
                && (
                    Consulta1[Category] = selectedCategory
                        || ISBLANK ( selectedCategory )
                )
        ),
        [Lost]
    )
RETURN lost

 

giammariam_1-1697575437697.png

 



Madison Giammaria
Proud to be a Super User 😄
LinkedIn

Do you frequently use Deneb to provide insights to your stakeholders? Have you considered sponsoring this free and open source custom visual? More info here!

View solution in original post

6 REPLIES 6
APR92
Frequent Visitor

@giammariam Hello,

First of all apologizes if the logic is not clear. Let me clarify:

I would like to determine how many customers I've lost this month versus the ones that I had the previous month only.

This means that any previous customer I had older than the previous month does't count. The comparison is month by month.

For example, I have to compare the customers that were active in february with the customers that were active in january.

 

The expected result right now is fine with the user granularity but the montly subtotals are not showing a proper value:

APR92_0-1697559764719.png

As you can see the subtotal "2023-02" is correct as is adding up user B and E that are lost.

The subtotal 2023-03 is wrong as is 0 and is not adding up the user C that is los (highlighted in green).


PS: Don't worry about the grand total as it is not needed in this measure.

 

Thank you very much, I highly appreciate your support! 🙂

Hey @APR92, there is probably a much cleaner way to do this, but try this:

Lost2 = 
VAR selectedDate =
    SELECTEDVALUE(Consulta1[Date])
VAR selectedCategory =
    SELECTEDVALUE(Consulta1[Category])
VAR tbl =
    ADDCOLUMNS (
        ADDCOLUMNS (
            Consulta1,
            "Active Last Month",
                MAXX (
                    FILTER (
                        ALL ( Consulta1 ),
                        Consulta1[Date] < EARLIER(Consulta1[Date])
                            && (
                                Consulta1[Category] = EARLIER(Consulta1[Category])
                                    || ISBLANK ( EARLIER(Consulta1[Category]) )
                            )
                    ),
                    Consulta1[Active]
                )
        ),
        "Lost",
            SWITCH (
                TRUE,
                ISBLANK ( [Active Last Month] ), BLANK (),
                [Active Last Month] < Consulta1[Active], 0,
                [Active Last Month] - Consulta1[Active]
            )
    )
VAR lost = 
    SUMX (
        FILTER (
            tbl,
            Consulta1[Date] = selectedDate
                && (
                    Consulta1[Category] = selectedCategory
                        || ISBLANK ( selectedCategory )
                )
        ),
        [Lost]
    )
RETURN lost

 

giammariam_1-1697575437697.png

 



Madison Giammaria
Proud to be a Super User 😄
LinkedIn

Do you frequently use Deneb to provide insights to your stakeholders? Have you considered sponsoring this free and open source custom visual? More info here!
giammariam
Solution Sage
Solution Sage

@APR92, this is because of the desired behavior was unclear. Overall for 2023-03 you had 4 currently active where you only had 3 active the month before. Since you still ended up with a total of more active than you did the previous month, the [Lost] metric is indicating that overall you didn't lose any for that month. Sounds like instead you want a total of any lost, regardless of what the overall picture is for that month. Now that I know that this is the desired behavior I'll try to get this implemented as soon as I get a chance. 



Madison Giammaria
Proud to be a Super User 😄
LinkedIn

Do you frequently use Deneb to provide insights to your stakeholders? Have you considered sponsoring this free and open source custom visual? More info here!
APR92
Frequent Visitor

I'm super stuck with it. Help please :$

I've played a little bit the past period measure, but the subtotals still wrong...

@giammariam 's response has the exact same issue with the lost's subtotals.

Users Lost Past Period =
VAR var1=
    CALCULATETABLE (
        VALUES ( CALC_userreport_Summarized[user_name] ),
        ALL(),
        PREVIOUSMONTH(CALC_userreport_Summarized[Date]),
        CALC_userreport_Summarized[user_name] = SELECTEDVALUE(CALC_userreport_Summarized[user_name])
    )

VAR var2 = COUNTROWS(var1)

VAR var3 =
    IF(
        var2 - [Users Past Period] = 0,
        BLANK(),
        var2 - [Users Past Period]
    )

RETURN
    var3
APR92
Frequent Visitor

@giammariam Hello, the subtotal for the period 2023-03 is not correct. The user granularity results is fine.

APR92_0-1697524512102.png

Thank you a lot for your time!

giammariam
Solution Sage
Solution Sage

Hey @APR92 try this. The negatives under the Lost field made it a bit confusing. I made some assumptions with the business rules:

  • If the prior date was the first date in the dataset, then [Lost] and [Past Month] are BLANK()
  • If Sum of Active is > [Past Month] then [Lost] = 0
  • If Sum of Active is <= [Past Month] then [Lost] = [Past Month] - [Active]
    • Note, if you want negatives in the [Lost] column, then you can switch this to [Active]-[Past Month]
  • The Subtotals for [Lost] follow the above rules as well

Let me know if any of these rules are incorrect.

giammariam_0-1697499572167.png

 

 

Past Month = 
VAR var1 =
    CALCULATE(
        SUM(Consulta1[Active]),
        PREVIOUSMONTH(Consulta1[Date])
    )

VAR maxDate = MAXX(
    ALLSELECTED(Consulta1),
    Consulta1[Date]
)

VAR sumMinusMaxDate = SUMX(
    FILTER(
        ALLSELECTED(Consulta1),
        Consulta1[Date] <> maxDate
    ),
Consulta1[Active]
)

RETURN
    IF(
        COUNTROWS(ALLSELECTED(Consulta1)) = COUNTROWS(Consulta1),
         sumMinusMaxDate,
         var1
    )

 

 

 

Lost = 
    VAR sumActive = SUM(Consulta1[Active])
    VAR var1 = SWITCH(
        TRUE,
        ISBLANK([Past Month]), BLANK(),
        sumActive<=[Past Month], [Past Month]-sumActive,
        sumActive>[Past Month], 0
        
    )

    RETURN
    var1

 

 

If this is enough to get you going please consider liking this reply and choosing it as the solution. Otherwise, I'm happy to help further.



Madison Giammaria
Proud to be a Super User 😄
LinkedIn

Do you frequently use Deneb to provide insights to your stakeholders? Have you considered sponsoring this free and open source custom visual? More info here!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

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.