Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Customers with 0 usage, Last 'x' months

Hi all,

 

I am looking to create a formula that counts (or flags) the number of customers that have had 0 usage within the last x months (where x can be changed if needed - for this example let x =2).

 

Here is my dataset.  If a customer does not have a contract anymore, then they simply do not appear for that particular month.  So if I wanted to return the count of customers that have had no usage in the last 2 months, I'd expect to see a count of 1 as only Sarah hasn't had any usage, whilst having an active contract.  Steve and Mary would not be counted as are not an active customer or have gaps.

 
 

 

CustomerDateUsage
BillJan-20100
SteveJan-200
SarahJan-2010
MaryJan-2010
JaneJan-2010
ElizabethJan-2025
BillFeb-2050
SteveFeb-200
SarahFeb-200
MaryFeb-200
JaneFeb-200
ElizabethFeb-2010
BillMar-2050
SarahMar-200
MaryMar-200
JaneMar-2010
BillApr-200
SarahApr-200
JaneApr-200
BillMay-2010
SarahMay-200
MaryMay-200
JaneMay-20100
BillMay-200
SarahMay-200
MaryMay-200
JaneMay-20100

 

I have been going round in circles a little bit with this one, especially looking at the lapsed customers DAX pattern, but the 'inactive' customers seem to be the sticking point. 

 

Any help would be much appreciated.

  • Anonymous's avatar
    Anonymous
    6 years ago

    Thank you both.  I think I have got the answer.

     

    Using Greg_Deckler's solution as the starting point and an idea from amitchandak., I have the following, which gives me the expected result.

     

    GregSolution =
    VAR __Table =
    SUMMARIZE(
    FILTER('Phone Usage','Phone Usage'[Date]<=DATE(2020,5,1) && [Date]>=EOMONTH(DATE(2020,5,1),-2)+1),
    [Customer],
    "__Usage",SUM([Usage]), "months", COUNTROWS('Phone Usage')
    )
    RETURN
    COUNTROWS(FILTER(__Table,[__Usage]=0 && [months] = 3))
     
    Really appreciate the help from you both

8 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    Anonymous - Maybe:

    Measure = 
      VAR __Table = 
        SUMMARIZE(
          FILTER('Table',[Date]<=TODAY() && [Date]>=EOMONTH(TODAY(),-3)+1),
          [Customer],
          "__Usage",SUM([Usage])
        )
    RETURN
      COUNTROWS(FILTER(__Table,[__Usage]=0))
  • Anonymous's avatar
    Anonymous
    Not applicable

    Thank you both.  I think I have got the answer.

     

    Using Greg_Deckler's solution as the starting point and an idea from amitchandak., I have the following, which gives me the expected result.

     

    GregSolution =
    VAR __Table =
    SUMMARIZE(
    FILTER('Phone Usage','Phone Usage'[Date]<=DATE(2020,5,1) && [Date]>=EOMONTH(DATE(2020,5,1),-2)+1),
    [Customer],
    "__Usage",SUM([Usage]), "months", COUNTROWS('Phone Usage')
    )
    RETURN
    COUNTROWS(FILTER(__Table,[__Usage]=0 && [months] = 3))
     
    Really appreciate the help from you both
  • Anonymous , With a date table.

    Now in you case have Date like

     

    Date = "01-" & [Month] // Mark data type as date

     

    example

    Rolling 3 have Usages= CALCULATE(sum(Table[Usages]),DATESINPERIOD('Date'[Date],max('Date'[Date]),-3,MONTH))
    Rolling 3 have Not Usages = if(CALCULATE(sum(Table[Usages]),DATESINPERIOD('Date'[Date],max('Date'[Date]),-3,MONTH)) +0>0,blank(),1)

     

    To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
    https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
    https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
    https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

    See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184


    Appreciate your Kudos.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thank you both for the quick replies, hugely appreciated.


    Funnily enough, the issue with both solutions, is that they both return a value of 2, as they are including Mary, but she didn't have a record in April and this should have 'reset' the count for her.  This is the same issue that I was hitting as I don't want to count the months that are blank, I want to have 'x' consecutive months where the usage is 0.

     

    Hope that makes sense.

    • amitchandak's avatar
      amitchandak
      Icon for Super User rankSuper User

      Anonymous , distinct count of the month and then count =3, if it rolling three, something like that?

    • Greg_Deckler's avatar
      Greg_Deckler
      Icon for Community Champion rankCommunity Champion

      Anonymous No, not entirely, please post expected output and why.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Sure no problem.  Here is the summarised table.  Mary in April has had a break in her contract and as such she has only has 1 consecutive month of 0 usage.  The count should return 1 as only Sarah in this example has had 3 consecutive months of (non broken) 0 usage.

     

    • Greg_Deckler's avatar
      Greg_Deckler
      Icon for Community Champion rankCommunity Champion

      Anonymous So like this? See attached PBIX file below sig. Page 15.

      Measure 15 = 
        VAR __Date = MAX('Table (15)'[Date])
        VAR __Users3Months = SELECTCOLUMNS(FILTER('Table (15)',[Date]>=EOMONTH(__Date,-2)+1 && [Date]<=EOMONTH(__Date,-1)),"Customer",[Customer])
        VAR __Table = 
          SUMMARIZE(
            FILTER('Table (15)',[Date]<=__Date && [Date]>=EOMONTH(__Date,-3)+1),
            [Customer],
            "__Usage",SUM([Usage])
          )
        VAR __Table1 = FILTER(__Table,[Customer] IN __Users3Months)
      RETURN
        COUNTROWS(FILTER(__Table1,[__Usage]=0))