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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
Jkaplan88
Regular Visitor

Find Latest sale date per Product as of a specified date

hi - new to PowerBI. i have a data set of products and sales by date. I'd like to be able to set a date filter which returns the latest sale date for each product on or before the specified date.

 

For example, if i specifcy 3/8/2020, id like to be able to return the entire row for each product below on or before 3/8/2020. Essentially trying to add an IF statement to a Max or LastDate but cnat figure out how to do it.

 

ProductProductIDSalesQuantityDate
AA115053/5/2020
BB125563/5/2020
CC120043/5/2020
DD11113/5/2020
EE130073/5/2020
FF130073/1/2020
AA115053/4/2020
CC120043/8/2020
EE130073/10/2020
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Jkaplan88,

If you want to filter the product data which the date is on or before specific date, you can use relative date slicer to make filter:

relative date slicer.JPG

In additional, you can create one measure to get the latest sale date of per product:

mDate = CALCULATE(max('Products'[Date]),ALLEXCEPT('Products','Products'[ProductID]))

latest sale date.JPG

Best Regards

Rena

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

Hi @Jkaplan88 ,

Whether your problem has been resolved? If yes, could you please mark the helpful post as Answered? Thank you.

Best Regards

Rena

Anonymous
Not applicable

Hi @Jkaplan88,

If you want to filter the product data which the date is on or before specific date, you can use relative date slicer to make filter:

relative date slicer.JPG

In additional, you can create one measure to get the latest sale date of per product:

mDate = CALCULATE(max('Products'[Date]),ALLEXCEPT('Products','Products'[ProductID]))

latest sale date.JPG

Best Regards

Rena

Greg_Deckler
Super User
Super User

@Jkaplan88 , I created a disconnected Calendar table and this measure:

 

Measure = 
    VAR __Max = MAX('Calendar'[Date])
RETURN
    IF(MAX('Table'[Date])<=__Max,1,0)

 

Used the measure as a filter. PBIX is attached.



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

thanks Greg. Im looking to just pull the latest sale information on or before the specified date. For example, if just looking at product A, if i select 3/8 on the date range, then im still seeing sales on March 5 and MArch 4. Im trying just to find the latest sale on or before 3/8.

 

thank you

jordan 

amitchandak
Super User
Super User

Did not get it completely. Can you share output need?

A measure like this can help you to get data on or before data

sales =
var _max = maxx(Table,Table[Date])
return
calculate(sum(table[Sales]),filter(all(Table),Table[Date]<=_max))

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

hi - sorry.  IF the user selected March 8, 2020 as the specified date, then the desired output table would be like this. Which returns the list of products and the latest respective sales data which occured on or before 3/8

 

3/8/2020    
ProductProductIDSalesQuantityDate
AA115053/5/2020
BB125563/5/2020
CC120043/8/2020
DD11113/5/2020
EE130073/5/2020
FF130073/1/2020

Updated PBIX to set Date to Latest to do the aggregation. Is this now correct?

 

 



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

unfortunately not. seems like in your example, 'prduct E' is getting filtered out due ot the measure. looks like because there is a later sale date occuring after 3/8 therefore the 'latest date' aggregator isnt picking it up.

@Jkaplan88 

For both sales and quantity create

 

Sales = 
var __maxdt =maxx(Table,table[Date])
VAR __id = MAX ( 'Table'[ProductID] )
VAR __date = CALCULATE ( MAX( 'Table'[Date] ), ALLSELECTED ( 'Table' ),  'Table'[ProductID] = __id ) 
RETURN CALCULATE ( sum ( 'Table'[Sales] ), VALUES ( 'Table'[ProductID] ), 'Table'[id] = __id, 'Table'[date] = __date ,'Table'[date] <= __maxdt )

Quantity = 
var __maxdt =maxx(Table,table[Date])
VAR __id = MAX ( 'Table'[ProductID] )
VAR __date = CALCULATE ( MAX( 'Table'[Date] ), ALLSELECTED ( 'Table' ),  'Table'[ProductID] = __id ) 
RETURN CALCULATE ( sum ( 'Table'[Quantity] ), VALUES ( 'Table'[ProductID] ), 'Table'[id] = __id, 'Table'[date] = __date ,'Table'[date] <= __maxdt )

 

 

Appreciate your Kudos.

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

Check out the April 2025 Power BI update to learn about new features.

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

Find out what's new and trending in the Fabric community.