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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
mkleifgen
Frequent Visitor

Calculated Column for New Customer

Hey everyone,

 

I am trying to create a calculated column that will return the document date of that particular sales line item IF this customer hasnt placed an order within the last 12 months. This constitutes a new account for us.

 

Opening Order = IF(CALCULATE(MAX(v_PBI_SalesData[Document Date]), FILTER(v_PBI_SalesData, v_PBI_SalesData[Customer Number] = EARLIER(v_PBI_SalesData[Customer Number]) && v_PBI_SalesData[SOP Number] < EARLIER(v_PBI_SalesData[SOP Number])) IN(DATESBETWEEN(v_PBI_SalesData[Document Date], v_PBI_SalesData[Document Date]-365, v_PBI_SalesData[Document Date]))), BLANK(), v_PBI_SalesData[Document Date])

The error that this currently has is: A function 'DATESBETWEEN' has been used in a True/False expression that is used as a table filter expression. This is not allowed.

 

This is the calculated column I have created, but can't quite get it to work. My logic is...

Return the document date of this sales line if the same customer number, while being an earlier order, IF the last order they placed wasn't within the last 12 months of this line item.

 

Let me know if this doesn't make sense.

-Mark

1 ACCEPTED SOLUTION
mkleifgen
Frequent Visitor

I figured out how to code my calculated column. I've split the DAX command into two calculated columns..

 

1.  Previous Order = CALCULATE(MAX(v_PBI_SalesData[Document Date]), FILTER(v_PBI_SalesData, v_PBI_SalesData[Customer Number] = EARLIER(v_PBI_SalesData[Customer Number]) && v_PBI_SalesData[SOP Number] < EARLIER(v_PBI_SalesData[SOP Number])))

This calculated column is simply returning the date of the previous order for this customer.

 

2. Opening Order = IF(v_PBI_SalesData[Previous Order]>v_PBI_SalesData[Document Date]-365, BLANK(), v_PBI_SalesData[Document Date])

The follow up calculated column is now returning a blank if the previous order to this order has been within the last year, OR returning the document date of the line if it is before 1 year ago.

View solution in original post

2 REPLIES 2
mkleifgen
Frequent Visitor

I figured out how to code my calculated column. I've split the DAX command into two calculated columns..

 

1.  Previous Order = CALCULATE(MAX(v_PBI_SalesData[Document Date]), FILTER(v_PBI_SalesData, v_PBI_SalesData[Customer Number] = EARLIER(v_PBI_SalesData[Customer Number]) && v_PBI_SalesData[SOP Number] < EARLIER(v_PBI_SalesData[SOP Number])))

This calculated column is simply returning the date of the previous order for this customer.

 

2. Opening Order = IF(v_PBI_SalesData[Previous Order]>v_PBI_SalesData[Document Date]-365, BLANK(), v_PBI_SalesData[Document Date])

The follow up calculated column is now returning a blank if the previous order to this order has been within the last year, OR returning the document date of the line if it is before 1 year ago.

Anonymous
Not applicable

You are trying to combine FILTER() with IN() , thats why you are getting the error. If you could post some sample data then we can derive the formula for you.

 

Thanks

Raj

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors