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

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
v-rzhou-msft
Community Support
Community Support

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
v-rzhou-msft
Community Support
Community Support

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

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.

Top Solution Authors