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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

values from current month not present in previos dates

I have made a table visual below:

shwetadalal_0-1637739261038.png

 

 

For each Sales Representative I want to calculate no of distinct clients in a month which are not present in dates before the particular month.

 

I wrote following measure but I am getting blank values:

 

New Clients =
var _mindate = MIN(Payments[TransactionDate])
var _maxdate = MAX(Payments[TransactionDate])
VAR CurrentMonthDistinctClients = CALCULATETABLE(VALUES(Contacts[UniqueID]),FILTER(Payments,Payments[TransactionDate]>=_mindate && Payments[TransactionDate] <= _maxdate))

VAR PreviousALLMonthsDistinctClients = CALCULATETABLE(VALUES(Contacts[UniqueID]),FILTER(Payments, Payments[TransactionDate] < _mindate))
Var NewClients = COUNTROWS(EXCEPT(CurrentMonthDistinctClients,PreviousMonthsDistinctClients))
RETURN
NewClients
 
 
Any help is appreciated.
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous 

My Sample is as below. I create a relationship between Fact table and Date table by Date column.

Fact Table:

1.png

Date table:

Date =
ADDCOLUMNS (
    CALENDARAUTO (),
    "Year", YEAR ( [Date] ),
    "Month", MONTH ( [Date] ),
    "YearMonth",
        YEAR ( [Date] ) * 100
            + MONTH ( [Date] ),
    "MonthYear", FORMAT ( [Date], "MMM 'YY" )
)

Try this code.

New Clients = 
VAR _RANGESTART = CALCULATE(MIN('Date'[Date]),ALLSELECTED('Date'))
VAR _RANGEEND = CALCULATE(MAX('Date'[Date]),ALLSELECTED('Date'))
VAR _CLIENT_LIST_BEFORE = CALCULATETABLE(VALUES('Table'[UniqueID]),FILTER(ALL('Table'),'Table'[Date]<_RANGESTART&&'Table'[Sales Representative]=MAX('Table'[Sales Representative])))
RETURN
CALCULATE(COUNT('Table'[UniqueID]),FILTER('Table',NOT('Table'[UniqueID] IN _CLIENT_LIST_BEFORE)))

Here I select my date slicer between 2021/03/01 to 2020/12/31.

Client in "A G" before date range are {C1,C2,C3}, so number of new client is 0.

Client in "C U" before date range are {C1,C2,C3,C5}, so number of new client (C4,C6) is 2.

Result is as below.

1.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous 

My Sample is as below. I create a relationship between Fact table and Date table by Date column.

Fact Table:

1.png

Date table:

Date =
ADDCOLUMNS (
    CALENDARAUTO (),
    "Year", YEAR ( [Date] ),
    "Month", MONTH ( [Date] ),
    "YearMonth",
        YEAR ( [Date] ) * 100
            + MONTH ( [Date] ),
    "MonthYear", FORMAT ( [Date], "MMM 'YY" )
)

Try this code.

New Clients = 
VAR _RANGESTART = CALCULATE(MIN('Date'[Date]),ALLSELECTED('Date'))
VAR _RANGEEND = CALCULATE(MAX('Date'[Date]),ALLSELECTED('Date'))
VAR _CLIENT_LIST_BEFORE = CALCULATETABLE(VALUES('Table'[UniqueID]),FILTER(ALL('Table'),'Table'[Date]<_RANGESTART&&'Table'[Sales Representative]=MAX('Table'[Sales Representative])))
RETURN
CALCULATE(COUNT('Table'[UniqueID]),FILTER('Table',NOT('Table'[UniqueID] IN _CLIENT_LIST_BEFORE)))

Here I select my date slicer between 2021/03/01 to 2020/12/31.

Client in "A G" before date range are {C1,C2,C3}, so number of new client is 0.

Client in "C U" before date range are {C1,C2,C3,C5}, so number of new client (C4,C6) is 2.

Result is as below.

1.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

amitchandak
Super User
Super User

@Anonymous , refer these two they can help

Customer Retention Part 5: LTD Vs Period Retention
https://community.powerbi.com/t5/Community-Blog/Customer-Retention-Part-5-LTD-and-PeriodYoY-Retention-is-only/ba-p/2114497

 

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

 

file is attached after signature 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.