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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
Eb50
Frequent Visitor

How to find the last selling date when the product hasn't been sold in the current month

Hi everyone,

 

I'm trying to get the last selling date for the combination of products & articles in a measure. I need the result to be linked to the current row context. I mean that if the product has been sold on May first (01-05) it should return a date prior to this date, and if I look at it on April first (01-04) it should also return a date prior to this date.

 

My data model is juste made of 4 tables, Sales, Calendar, product & customers. Calendar, Customers and Products linked to sales.

 

I found a formula that works partially :  

 

Last_Selling_Date:=

VAR Maxdate = CALCULATE(LASTDATE(Sales[Date]);FILTER(ALLEXCEPT(Sales;Products;Articles);Sales[Date]<MIN(Sales[Date])))

RETURN

Maxdate

 

My problem now, is that the formula works when the product has been sold to the customer this month, but it doesn't work if there hasn't been any sales. There is the results I obtain with the above formula, I've put red crosses where the formula isn't working.

 

Eb50_0-1717777089227.png

 

For product 10 & 11 I know for a fact (by checking my data) that a previous date exits. 

 

Now I think I understand that the filter function create a row context, and obviously if the row with the product and the article doesn't exist on this particular month, it will not show anything.  

 

How can I solve this problem ? I thought about generating a table with unique values from the calendar table, the product table, and the customer table and then adding a measure giving me the €/Per unit (measure from the sales table). I thought that it would give me a table with all existing values that I could iterate over next but ... I failed to find a solution to do that (if it's a good solution)

 

I'm using PowerPivot on Excel.

 

I hope I was clear enough, thanks for reading me !

 

 

2 REPLIES 2
Anonymous
Not applicable

Hi @Eb50 ,

Based on the description, try to modify the dax formula to the following.

Last_Selling_Date = 
VAR CurrentProductArticle = SELECTEDVALUE(Products[ProductID]) & SELECTEDVALUE(Articles[ArticleID])
VAR MaxDateContext = MAX(Calendar[Date])
VAR RelevantSales = 
    FILTER(
        ALL(Sales),
        Sales[ProductID] & Sales[ArticleID] = CurrentProductArticle
        && Sales[Date] < MaxDateContext
    )
VAR LastSaleDate = MAXX(RelevantSales, Sales[Date])
RETURN
    LastSaleDate

 

Best Regards,

Wisdom Wu

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

Greg_Deckler
Community Champion
Community Champion

@Eb50 Perhaps try removing the < MIN('Sales'[Date]) ? That's the only thing I see that could be excluding things.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.