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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Lamdasquare
Regular Visitor

Last 8 dates/weeks of data

Hello Forum!  

 

Newbie here, been spinning my head on this for a few days so thought i'd post here.  Trying to pull the last 8 dates/weeks from my dataset.  I'm not sure if I have to create a date table to do this or if some form of calculate will make it work - i've been trying a few calculate statements, datesinperiod but it seems to pull all 9 values that I currently have instead of just the 8 I think it should so my forumla seems off.  

What my table has is a date column, sales, geo, and category.  The date is not daily but a weekly date - so it gives every 7th day date - from Monday I believe so the dates would look like, for example, Jan 1, Jan 8, Jan 15, Jan 22.... etc.  

I'm trying to put together a visual that will show the last 8 dates/weeks of data broken out by category and this will change obviously from week to week as a new weeks worth of data comes in once its refreshed so it has to be rolling.  Is it possible to do some sort of calc on the date field to just do a -8 and get it to work?  I even thought of using a weeknum column but I wasn't able to get that to work either.

 

Thanks for any responses/help!!

1 ACCEPTED SOLUTION

you can create a column

 

Column = if('Table'[Date]>=(max('Table'[Date])-56),"y")
 
11.PNG
 
then you add the column to the visual filter and select y
 
12.PNG
 
pls see the attachment below




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @Lamdasquare 

 

@ryan_mayu Thank you very much for your prompt reply. Please allow me to share some other methods here.

 

Create a measure to dynamically sort dates. And look for the top eight data.

 

Last 8 weeks Sales = 
var _rank = RANKX(ALL('Table'), CALCULATE(MAX('Table'[Date])),, DESC, Dense)
RETURN
IF(
    _rank <= 8,
    SELECTEDVALUE('Table'[Sales]),
    BLANK()
)

 

Here is the result.

 

vnuocmsft_0-1722926671406.png

 

Regards,

Nono Chen

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

ryan_mayu
Super User
Super User

could you pls provide some sample data and expected output?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Sure - here is a sample table:  We will assume for this table the date is the week after 3/11 so 3/11 is the last updated value.  The first few give you an idea of the data - for simplicity sake I just used the next weeks dates to show you a table of 11 weeks of data and I am looking to pull the last 8 weeks of data from 3/11 backwards.  

 

DateGeoCategorySales
1/1/2024US14
1/1/2024Canada15.3
1/1/2024England12
1/1/2024France11
1/1/2024US22
1/1/2024Canada23.4
1/1/2024England26
1/1/2024France29
1/7/2024US31
1/7/2024Canada31
1/7/2024England32
1/7/2024France33
1/14/2024US14
1/14/2024Canada15.3
1/14/2024England12
1/14/2024France11
1/21/2024US22
1/28/2024Canada23.4
2/4/2024England26
2/11/2024France29
2/18/2024US31
2/25/2024Canada31
3/4/2024England32
3/11/2024France33


So I would expect to pull all data from 3/11 back to 1/21 as that is 8 weeks worth of data.  So then when I put it into a line chart visual it will have the categories going up/down in zig zaggy lines by Geo with the 8 dates showing on the bottom to show how each category is changing by week.  

you can create a column

 

Column = if('Table'[Date]>=(max('Table'[Date])-56),"y")
 
11.PNG
 
then you add the column to the visual filter and select y
 
12.PNG
 
pls see the attachment below




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks Ryan - that worked although with a funny side effect.  I see what you were doing there with the -56 as 8x7 but it would return 9 weeks of data instead of 8 so I had to lower it to 49 days instead of 56.  
v-nuoc - for some reason when I created your measure and then put it into my visual - it errors out eventhough the code is a match.  

you are welcome





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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