Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hello, I need to calculate 2 values using DAX function.
1. Calculate the penultimate date for product id
2. Calculate the quantity for a given date and product id.
an example table with data is attached.
I will be grateful for your help.
id prod date qty
| 82 | 17.04.2023 | 4 |
| 801 | 17.04.2023 | 5 |
| 632 | 17.04.2023 | 11 |
| 632 | 17.04.2023 | 11 |
| 5583-2 | 17.04.2023 | 3 |
| 5583-1 | 17.04.2023 | 3 |
| 5536 | 17.04.2023 | 30 |
| 5535 | 17.04.2023 | 9 |
| 5533 | 17.04.2023 | 9 |
| 5531 | 17.04.2023 | 9 |
| 5528-1 | 17.04.2023 | 20 |
| 5527-4 | 17.04.2023 | 1 |
| 5526-4 | 16.04.2023 | 6 |
| 5526-3 | 16.04.2023 | 6 |
| 5526-1 | 16.04.2023 | 6 |
| 5525-3 | 16.04.2023 | 20 |
| 5525-1 | 16.04.2023 | 20 |
| 5523-2 | 16.04.2023 | 26 |
| 5522 | 16.04.2023 | 4 |
| 5521 | 16.04.2023 | 4 |
| 5517 | 16.04.2023 | 4 |
| 5516 | 16.04.2023 | 8 |
| 5515 | 16.04.2023 | 5 |
| 5510-5 | 16.04.2023 | 4 |
| 5486 | 16.04.2023 | 12 |
| 5485 | 16.04.2023 | 12 |
| 5481 | 15.04.2023 | 12 |
| 5423 | 15.04.2023 | 2 |
| 5421 | 15.04.2023 | 1 |
| 5415 | 15.04.2023 | 10 |
| 5309-1 | 15.04.2023 | 1 |
| 5280 | 15.04.2023 | 10 |
| 5261 | 15.04.2023 | 2 |
| 525-2 | 15.04.2023 | 3 |
| 525-1 | 15.04.2023 | 5 |
| 524 | 15.04.2023 | 96 |
| 5226-1 | 15.04.2023 | 3 |
| 5220-2 | 15.04.2023 | 6 |
| 522 | 15.04.2023 | 96 |
| 5219-1 | 15.04.2023 | 10 |
| 5217-1 | 15.04.2023 | 5 |
| 5215-2 | 14.04.2023 | 1 |
| 518-2 | 14.04.2023 | 30 |
| 518-1 | 14.04.2023 | 50 |
| 5043-5 | 14.04.2023 | 1 |
| 5043-4 | 14.04.2023 | 1 |
| 5043-3 | 14.04.2023 | 4 |
| 5043-1 | 14.04.2023 | 1 |
| 5041-3 | 14.04.2023 | 1 |
| 5041-1 | 14.04.2023 | 6 |
| 5040-3 | 14.04.2023 | 2 |
| 5038-4 | 14.04.2023 | 1 |
| 4991-1 | 14.04.2023 | 1 |
| 492 | 14.04.2023 | 2 |
| 485 | 14.04.2023 | 8 |
| 4814 | 14.04.2023 | 84 |
| 478 | 14.04.2023 | 30 |
| 472 | 14.04.2023 | 2 |
| 471 | 14.04.2023 | 10 |
| 468 | 13.04.2023 | 10 |
| 467 | 13.04.2023 | 30 |
| 465 | 13.04.2023 | 10 |
| 4647 | 13.04.2023 | 24 |
| 4645 | 13.04.2023 | 48 |
| 4614 | 13.04.2023 | 10 |
| 4575 | 13.04.2023 | 2 |
| 4450 | 13.04.2023 | 5 |
| 4245 | 13.04.2023 | 12 |
| 4224 | 13.04.2023 | 10 |
| 4207-2 | 13.04.2023 | 1 |
| 4132 | 13.04.2023 | 10 |
| 4119 | 13.04.2023 | 5 |
| 3895 | 13.04.2023 | 8 |
| 3868 | 13.04.2023 | 4 |
| 3863 | 13.04.2023 | 6 |
Hello, actually the data was wrong. I am pasting the corrected ones now.
In this list, the maximum date is 24/04/2023.
However, I want to be able to calculate the next e.g.
22/04/2023 (max-1) and another 17/04/2023 (max-2), i.e. subsequent dates in a decreasing sequence. The function must include a filter for a specific product id.
At the same time, the result of this function is supposed to be a filter to find other values from a table row.
e.g.
date 22/04.2023 for product id 25, is to be a filter to the sales quantity for a given date and product id.
The data is still not good. There is no overlap.
your sample data only contains one date per product id, so we cannot compute the penultimate date.
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 19 | |
| 10 | |
| 9 | |
| 4 | |
| 4 |
| User | Count |
|---|---|
| 31 | |
| 31 | |
| 20 | |
| 12 | |
| 12 |