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

Smart people needed (a date classification issue)

Hi All,

 

I have a kind of classification issue. Our department wants to distinguish between New and Existing (bestaande) business.

- New Business is classified as the first date on which there is turnover + 365 days.

- After a 365 days period, starting at the first date, the turnover is classified as 'Bestaande Business' or in English existing business.

 

This is simply done by the following formula ( IF(Easyflex_data[ndate] < (Easyflex_data[MinDate EF] + 365) ; "New Business"; "Bestaande Business").

But our department has another rule, which is: If the business has a discontinuity greater than 365 days (of no turnover), than the turnover must get the label new business again. See the following example:

Good classification of new business

1.png
The first row of turnover for this client is correctly classified as new business

Good classification of existing (bestaande business)

2.png

A example of a good transition from New tot Existing (bestaande business) on 04-01-2016.

Bad classification of existing business after a discontinuity periode 

3.png

from 28-08-2017 the turnover has to be classified as new business again because the discontinuity period is longer than 365 days. (04-04-2016 and 28-08-2017). Than the turnover has to be classified as new business till 28-08-2018 (which is one year or 365 days later). Thus 30-10-2017 and 06-11-2017 are wrongly classified as existing (bestaande) business.

Who can help me out with the right formula? 
Many thanks in advance. 

Ronald

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @Vvelarde,

Thank you very much, we are almost there. 

This works wonderful for a database with a single client. But we encounter a database with multiple clients, thus we have to add another argument to the formula. Something like:

Easyflex_data[RlIdNr] = EARLIER(Easyflex_data[RlIdNr]

I'm trying to add this to your min +365 formula, but i can't figure out how to add a second filter argument:

MinDate + 365 = 
VAR _ContextDate= Easyflex_data[ndate]
VAR FilteredTable= FILTER(Easyflex_data;Easyflex_data[ndate] <= _ContextDate && Easyflex_data[Discontinued]="Yes")
VAR _Exist_PreviousDiscountinued = COUNTROWS(FilteredTable)
VAR Result = If (_Exist_PreviousDiscountinued > 0; CALCULATE(MAX(Easyflex_data[ndate]);TOPN(1;FilteredTable;[ndate];DESC));Easyflex_data[MinDate EF])
RETURN
Result + 365

 Like this?

 FILTER(ALL(Easyflex); Easyflex_data;Easyflex_data[ndate] <= _ContextDate && Easyflex_data[Discontinued]="Yes"); Easyflex_data[RlIdNr] = EARLIER(Easyflex_data[RlIdNr]))

 Many thanks!

Ronald

View solution in original post

@Anonymous

 

Try with :

VAR FilteredTable= FILTER(Easyflex_data;Easyflex_data[ndate] <= _ContextDate && Easyflex_data[Discontinued]="Yes" && EasyFlex_Data[RIIdNr]=EARLIER (EasyFlex_Data[RIIdNr]) ) 

 Regards

 

Victor




Lima - Peru

View solution in original post

6 REPLIES 6
KarelV
New Member

Hi All!

 

I'm a colleague of Ronald, who initiated this thread. We are still facing the same problem. Today we wrote a new formula using the 'EARLIER' function in DAX for our calculated column. We seem to keep getting an error because the column name we are trying to refer to in the formula can't be found. 

image (1).png

 

 

 

 

What we are trying to do with the PREVIOUS function is actually what the 'LAG' function in R would do. Do any of you know if we are using the 'PREVIOUS' function in a wrong way? 

 

We would really appreciate your input!

 

All the best, 

 

Karel

Vvelarde
Community Champion
Community Champion

@KarelV @Anonymous

 

Hi, please review the PBIX.

 

Let me know if works on your scenario

 

Regards

 

Victor




Lima - Peru
Anonymous
Not applicable

Hi @Vvelarde,

Thank you very much, we are almost there. 

This works wonderful for a database with a single client. But we encounter a database with multiple clients, thus we have to add another argument to the formula. Something like:

Easyflex_data[RlIdNr] = EARLIER(Easyflex_data[RlIdNr]

I'm trying to add this to your min +365 formula, but i can't figure out how to add a second filter argument:

MinDate + 365 = 
VAR _ContextDate= Easyflex_data[ndate]
VAR FilteredTable= FILTER(Easyflex_data;Easyflex_data[ndate] <= _ContextDate && Easyflex_data[Discontinued]="Yes")
VAR _Exist_PreviousDiscountinued = COUNTROWS(FilteredTable)
VAR Result = If (_Exist_PreviousDiscountinued > 0; CALCULATE(MAX(Easyflex_data[ndate]);TOPN(1;FilteredTable;[ndate];DESC));Easyflex_data[MinDate EF])
RETURN
Result + 365

 Like this?

 FILTER(ALL(Easyflex); Easyflex_data;Easyflex_data[ndate] <= _ContextDate && Easyflex_data[Discontinued]="Yes"); Easyflex_data[RlIdNr] = EARLIER(Easyflex_data[RlIdNr]))

 Many thanks!

Ronald

@Anonymous

 

Try with :

VAR FilteredTable= FILTER(Easyflex_data;Easyflex_data[ndate] <= _ContextDate && Easyflex_data[Discontinued]="Yes" && EasyFlex_Data[RIIdNr]=EARLIER (EasyFlex_Data[RIIdNr]) ) 

 Regards

 

Victor




Lima - Peru
Gazzer
Resolver II
Resolver II

I feel like you need to do is compare MaxDate to today to see if it should be reverted to New Business.

 

Something like this?

IF( Easyflex_data[ndate] < (Easyflex_data[MinDate EF] + 365) OR Easyflex_data[MaxDate EF] < Today() ; "New Business" ; "Bestaande Business")

Anonymous
Not applicable

Hi @Gazzer,

Unfortunately, this solution does not work. Because the max-date relates to the last date we have from a customer in the database.

Do you have any more ideas? Maybe something with a variable or something like that?

 

Ronald

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.