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

How to Exclude specific customers for relative dates and count residuals ?

Hi all,

 

I have a dataset as below.

CustomerNoCategoryInvoiceDate
000001A1.05.2020
000002B15.05.2020
000003A22.05.2020
000004A10.06.2020
000005A15.06.2020
000006B18.06.2020
000007A22.06.2020
000005A7.07.2020
000009A30.07.2020
000010A10.08.2020
000007A20.08.2020
000003B10.09.2020
000013A12.09.2020
000004A13.09.2020
000001A14.09.2020

 

As you can see there are customers, category and Invoice date fields. Invoice date means the customers transaction date. It might be more tane one invoice date for one Customer.
My requierment is the number of customers who have transaction within the last 6 months but not in the last 1 month
I want to exclude the customers from dataset which one have a transaction in last 1 month then distinct count others.
In my example these customers are 
"000007"
"000003"
"000013"
"000004"
"000001"
after i eliminated these customers from my dataset the final view is like that;

CustomerNoCategoryInvoiceDate
000002B15.05.2020
000005A15.06.2020
000006B18.06.2020
000005A7.07.2020
000009A30.07.2020
000010A10.08.2020

 

Then i can make the calculation like that,

 

Metric = CALCULATE (
    DISTINCTCOUNT ( 'Table'[CustomerNo] ),
    FILTER (
        'Table',
        'Table'[Category] = "A"
            && 'Table'[InvoiceDate]
                > TODAY () - 90))

 


In my example this metric should be return 3.
I need help for first part. I don't have any idea how can i filter the customers and summarized the dataset like that.
If you have another solution like don't summarized and just create a metric that is fine, it doesn't matter.
Any solution is suitable.


2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

@Anonymous Try something like this:

Measure = 
  VAR __LastMonth = DISTINCT(SELECTCOLUMNS(FILTER('Table',[InvoiceDate]<=TODAY() && [InvoiceDate]>=DATE(YEAR(EOMONTH(TODAY(),-1)),MONTH(EOMONTH(TODAY(),-1)),DAY(TODAY()),"Customer",[Customer]))
  VAR __LastSixMonths = DISTINCT(SELECTCOLUMNS(FILTER('Table',[InvoiceDate]<=TODAY() && [InvoiceDate]>=DATE(YEAR(EOMONTH(TODAY(),-6)),MONTH(EOMONTH(TODAY(),-6)),DAY(TODAY()),"Customer",[Customer]))
  VAR __FinalTable = EXCEPT(__LastSixMonths,__LastMonth)
RETURN
  COUNTROWS(__FinalTable)

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

View solution in original post

AiolosZhao
Memorable Member
Memorable Member

Hi @Anonymous ,

 

Hope the below measure is what you want:

 

How to Exclude specific customers for relative dates and count residuals.PNG

 

Measure 15 = CALCULATE(DISTINCTCOUNT('Table (4)'[CustomerNo]),FILTER('Table (4)','Table (4)'[Category] = "A")) - CALCULATE(DISTINCTCOUNT('Table (4)'[CustomerNo]),FILTER('Table (4)','Table (4)'[InvoiceDate] <= DATE(YEAR(NOW()),MONTH(NOW()) - 6,DAY(NOW())) || 'Table (4)'[InvoiceDate] >= DATE(YEAR(NOW()),MONTH(NOW()) - 1,DAY(NOW()))))

 

Aiolos Zhao





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
AiolosZhao
Memorable Member
Memorable Member

Hi @Anonymous ,

 

Hope the below measure is what you want:

 

How to Exclude specific customers for relative dates and count residuals.PNG

 

Measure 15 = CALCULATE(DISTINCTCOUNT('Table (4)'[CustomerNo]),FILTER('Table (4)','Table (4)'[Category] = "A")) - CALCULATE(DISTINCTCOUNT('Table (4)'[CustomerNo]),FILTER('Table (4)','Table (4)'[InvoiceDate] <= DATE(YEAR(NOW()),MONTH(NOW()) - 6,DAY(NOW())) || 'Table (4)'[InvoiceDate] >= DATE(YEAR(NOW()),MONTH(NOW()) - 1,DAY(NOW()))))

 

Aiolos Zhao





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Greg_Deckler
Super User
Super User

@Anonymous Try something like this:

Measure = 
  VAR __LastMonth = DISTINCT(SELECTCOLUMNS(FILTER('Table',[InvoiceDate]<=TODAY() && [InvoiceDate]>=DATE(YEAR(EOMONTH(TODAY(),-1)),MONTH(EOMONTH(TODAY(),-1)),DAY(TODAY()),"Customer",[Customer]))
  VAR __LastSixMonths = DISTINCT(SELECTCOLUMNS(FILTER('Table',[InvoiceDate]<=TODAY() && [InvoiceDate]>=DATE(YEAR(EOMONTH(TODAY(),-6)),MONTH(EOMONTH(TODAY(),-6)),DAY(TODAY()),"Customer",[Customer]))
  VAR __FinalTable = EXCEPT(__LastSixMonths,__LastMonth)
RETURN
  COUNTROWS(__FinalTable)

@ 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 ,  Join invoice date with date table have measures like

 

Rolling 6 Sales = CALCULATE(Count(Table[CustomerNo]),DATESINPERIOD('Date'[Date],max('Date'[Date]),-6,MONTH))

MTD = calculate(Count(Table[CustomerNo]),datesmtd('Date'[Date]))

Lost Customer  = Sumx(VALUES(Customer[Customer Id]),if(ISBLANK([MTD]) && not(ISBLANK([Rolling 3 Sales])) , 1,BLANK()))

 

Refer

https://community.powerbi.com/t5/Community-Blog/Customer-Retention-Part-1-Month-on-Month-Retention/ba-p/1361529

 

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.