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!Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!
Please help me with the DAX code of extracting sale of 7 days prior of the date selected
Solved! Go to Solution.
Hi, @UrmiC ;
First you should have a calendar table , then create a flag measure ,apply it into filter.
1. create a calendar table.
Table = CALENDAR(DATE(2021,1,1),TODAY())
2.slicer date use other table and two tables don't have relationship.then create a flag measure.
flag = IF(MAX([Date]) <MAX('slicer'[Date])&&MAX([Date])>=MAX('slicer'[Date])-7,1,0)
3.apply the flag measure into filter.
The final output is shown below:
Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Simple Way: You just need to grab the date 7 days ago, and then use that to filter with a bigger than.
So say you are using the UTCNOW() function to get the time in UTC for right now. This will return something in the Datetime type.
You would then create a seperate DAX measure or a variable by doing the following:
UTCNOW() -7
This will return the timestamp exactly 7 days ago in UTC, you can then just use the {date (assume UTC)} > (UTCNOW()-7) && {date (assume UTC)} < UTCNOW()
Hi, @UrmiC ;
First you should have a calendar table , then create a flag measure ,apply it into filter.
1. create a calendar table.
Table = CALENDAR(DATE(2021,1,1),TODAY())
2.slicer date use other table and two tables don't have relationship.then create a flag measure.
flag = IF(MAX([Date]) <MAX('slicer'[Date])&&MAX([Date])>=MAX('slicer'[Date])-7,1,0)
3.apply the flag measure into filter.
The final output is shown below:
Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,
These should work
Total sales = sum(Data[sales])
Total sales 7 days prior = calculate([total sales],datesbetween(calendar[date],min(calendar[date])-7,min(calendar[date])-7))
The slicer should carry the date from the Calendar Table. Select any one date in the slicer.
Please provide sanitized sample data in usable format (not as a picture - inserting it into a table would be good) and show the expected outcome.
Vote for your favorite vizzies from the Power BI World Championship submissions!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 56 | |
| 52 | |
| 45 | |
| 17 | |
| 16 |
| User | Count |
|---|---|
| 108 | |
| 108 | |
| 39 | |
| 33 | |
| 25 |