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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare 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
v-yiruan-msft
Community Support
Community Support

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

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

View solution in original post

9 REPLIES 9
v-yiruan-msft
Community Support
Community Support

Hi @Jkaplan88 ,

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

Best Regards

Rena

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-yiruan-msft
Community Support
Community Support

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

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
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))

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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