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
simonGIS
Helper I
Helper I

Flag New Clients using Opportunity Date field

I am pulling some data from Salesforce into PowerBI.

 

  • I have an Account Table:
IdName
12ABC Motors
13Tesla
14Toyota

 

  • And a 1:M relationship setup with the Opportunity table:
AccountIdStageNameAmountCloseDate
12Closed Lost504001/04/2018
12Closed Lost175027/06/2019
13Closed Lost340008/12/2018
13Closed Won10000030/11/2018
13Closed Won109012/05/2019
14Closed Lost1072016/03/2018
14Closed Won341020/05/2019

 

I believe a new customer can be defined as:

  • If the minimum CloseDate of all Opportunity.StageName = ClosedWon, is within the last 3 months = True, otherwise False.
  • In the above example:
IdNameNew Customer
12ABC MotorsFalse
13TeslaFalse
14ToyotaTrue

 


I think it would make sense to calculate this in the Query Editor using Power Query M expression on the Account table to define a new field, but open to suggestions and alternative option using DAX in the Data View.

 

I am new to Power BI and still running through some online tutorials, but would really appreciate some pointers on how to achieve this.  

 

I saw some other posts talking about creating separate calendar tables, but I do not think I need to do this.

 

The end goal will be to leverage this value to show in charts to highlight the new vs existing clients we have by territory.

1 ACCEPTED SOLUTION
Iamnvt
Continued Contributor
Continued Contributor

hi,

 

if you want to slice anything, you need to use it as Calculated Column:

New customers - Calculated Column = 
VAR
lastwindate = CALCULATE(LASTNONBLANK(Opportunity[CloseDate],0), FILTER(ALL(Opportunity), Opportunity[AccountId] = EARLIER(Opportunity[AccountId]) && Opportunity[StageName] = "Closed Won"))
RETURN
IF(OR(DATEDIFF(lastwindate, TODAY(),MONTH) >3, lastwindate = BLANK()), "FALSE", "TRUE")

if you don't want to slice, then Measure is fine:

New Customer - Measure = 
VAR
closestwindate3 = 
CALCULATE(LASTNONBLANK('Calendar'[Date],0), FILTER('Calendar',CALCULATE(SUM(Opportunity[Amount])>0) && FIRSTNONBLANK(Opportunity[StageName],0) = "Closed Won"))
VAR
result =
IF(OR(DATEDIFF(closestwindate3,TODAY(),MONTH) > 3, closestwindate3 = BLANK()), "FALSE", "TRUE")
return
result

here is the PBI file.

https://1drv.ms/u/s!Aps8poidQa5zk6puzgZlCXbVuvWU_w

View solution in original post

10 REPLIES 10
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thats great!  What is the right order of steps to replicate that?

 

Create a Query and plug in 

Calendar = CALENDAR(MIN(Opportunity[CloseDate]),MAX(Opportunity[CloseDate]))
 
Join the Calendar back to the Opps table?

 

You are welcome.  If my reply helped, please mark it as Answer.  Yes, that is the right order.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Struggling a little to reverse engineer.

I understand the new measures ok.

 

But what are the specific steps to generate the Calendar table.

 

Where do I plug the following expression?

Calendar = CALENDAR(MIN(Opportunity[CloseDate]),MAX(Opportunity[CloseDate]))
 
New table from a DAX expression?

By going to Modelling > New Table.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks.  Got it semi-working with my data.

 

The end goal will be to leverage this value to show in charts to highlight the new vs existing clients

e.g. Bar Chart of clients, stacked by existing/new

 

With your dashboard, I can't use the New Customer field for any of the visualisation filters or legends.

 

If I wanted to create some charts using the New Customer field, it appears to not like using the NewClient measure.  It works fine in the table as an additional column, but trying to use it to distinguish new clients in both a bar chart and a shape map, it fails to let me use it.

 

I have tried recreating the measures under the Account table, but it still won't let me use the New Customer measure in my visulisations.

 

Would a better approach be to create a new field in data view for the account table, and somehow create a confitional expression in a new column that uses logic similar to your previous formula?

I can create a new column and use this expression:

 

NewClient6mths =
IF(AND(DATEDIFF([Date of first win],TODAY(),MONTH)<=6,[Date of first win]<>BLANK()), "NEW", "NOT NEW")

 

Can you comment on this approach?

 

1.jpg

That would not be a good approach.  If you show New and Old via a calculated column formula (as opposed to a measure which is my existing solution), the formula will not recalculate when filter/slicers are changed.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Ok.  Thanks. 

So how can I get your new measure to allow for creating charts.  It is not allowing me to use it.

Iamnvt
Continued Contributor
Continued Contributor

hi,

 

if you want to slice anything, you need to use it as Calculated Column:

New customers - Calculated Column = 
VAR
lastwindate = CALCULATE(LASTNONBLANK(Opportunity[CloseDate],0), FILTER(ALL(Opportunity), Opportunity[AccountId] = EARLIER(Opportunity[AccountId]) && Opportunity[StageName] = "Closed Won"))
RETURN
IF(OR(DATEDIFF(lastwindate, TODAY(),MONTH) >3, lastwindate = BLANK()), "FALSE", "TRUE")

if you don't want to slice, then Measure is fine:

New Customer - Measure = 
VAR
closestwindate3 = 
CALCULATE(LASTNONBLANK('Calendar'[Date],0), FILTER('Calendar',CALCULATE(SUM(Opportunity[Amount])>0) && FIRSTNONBLANK(Opportunity[StageName],0) = "Closed Won"))
VAR
result =
IF(OR(DATEDIFF(closestwindate3,TODAY(),MONTH) > 3, closestwindate3 = BLANK()), "FALSE", "TRUE")
return
result

here is the PBI file.

https://1drv.ms/u/s!Aps8poidQa5zk6puzgZlCXbVuvWU_w

Hi,

Is this the result you are expecting?  Check the revenue earned figure as well.

Untitled.png

If yes, then share a larger dataset so that i can scheck the accuracy.  Also, share other columns that you have have such as territory which you would like to slice/filter your visual by.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.