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
Anonymous
Not applicable

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.

1 ACCEPTED SOLUTION
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

View solution in original post

8 REPLIES 8
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
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.

 

usage_summary.png

@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))

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
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.

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

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


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

@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))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

@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.

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.