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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
UrmiC
New Member

extracting sale of 7 days prior of the date selected

Please help me with the DAX code of extracting sale of 7 days prior of the date selected

 
1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

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.

vyalanwumsft_0-1632466039943.png

flag = IF(MAX([Date]) <MAX('slicer'[Date])&&MAX([Date])>=MAX('slicer'[Date])-7,1,0)

3.apply the flag measure into filter.

vyalanwumsft_1-1632466120402.png

The final output is shown below:

vyalanwumsft_2-1632466161716.png

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.

View solution in original post

4 REPLIES 4
durack99
Advocate I
Advocate I

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()

v-yalanwu-msft
Community Support
Community Support

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.

vyalanwumsft_0-1632466039943.png

flag = IF(MAX([Date]) <MAX('slicer'[Date])&&MAX([Date])>=MAX('slicer'[Date])-7,1,0)

3.apply the flag measure into filter.

vyalanwumsft_1-1632466120402.png

The final output is shown below:

vyalanwumsft_2-1632466161716.png

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.

Ashish_Mathur
Super User
Super User

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.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
lbendlin
Super User
Super User

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.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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