Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
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.
| Product | ProductID | Sales | Quantity | Date |
| A | A1 | 150 | 5 | 3/5/2020 |
| B | B1 | 255 | 6 | 3/5/2020 |
| C | C1 | 200 | 4 | 3/5/2020 |
| D | D1 | 11 | 1 | 3/5/2020 |
| E | E1 | 300 | 7 | 3/5/2020 |
| F | F1 | 300 | 7 | 3/1/2020 |
| A | A1 | 150 | 5 | 3/4/2020 |
| C | C1 | 200 | 4 | 3/8/2020 |
| E | E1 | 300 | 7 | 3/10/2020 |
Solved! Go to Solution.
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:
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]))Best Regards
Rena
Hi @Jkaplan88 ,
Whether your problem has been resolved? If yes, could you please mark the helpful post as Answered? Thank you.
Best Regards
Rena
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:
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]))Best Regards
Rena
@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.
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
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))
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 | ||||
| Product | ProductID | Sales | Quantity | Date |
| A | A1 | 150 | 5 | 3/5/2020 |
| B | B1 | 255 | 6 | 3/5/2020 |
| C | C1 | 200 | 4 | 3/8/2020 |
| D | D1 | 11 | 1 | 3/5/2020 |
| E | E1 | 300 | 7 | 3/5/2020 |
| F | F1 | 300 | 7 | 3/1/2020 |
Updated PBIX to set Date to Latest to do the aggregation. Is this now correct?
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.
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.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 53 | |
| 37 | |
| 35 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 74 | |
| 70 | |
| 39 | |
| 35 | |
| 23 |