cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper V
Helper V

Table with last 4 weeks data

Hello all
I have a table with week number, Sales, Costs and profits.
I would love to see, only the last 4 weeks, like this example, which are filtered from the date filter:
Capture.JPG
Thanks in advance guys
Best regards

Pedro

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Microsoft
Microsoft

Re: Table with last 4 weeks data

Hi @pedromooji ,

 

We can use two ways to meet your requirement.

 

1. Create a calculate column first to get the week number.

 

week = RIGHT('Table'[year&week],LEN('Table'[year&week])-FIND("-",'Table'[year&week],1,1))

 

Table 1.jpg

 

Then we can create a measure based on [week].

 

Measure = 
var last_week = MAXX(ALLSELECTED('Table'),'Table'[week])
var Last_four_week = last_week-4
return 
CALCULATE(SUM('Table'[values]),FILTER('Table','Table'[week]>Last_four_week && 'Table'[week]<=last_week))

 

And we can put the [year & week] and [Measure] in a table visual.

 

Table 2.jpg

 

2. We can use Filters on this visual to get the result.

 

Also we need the week number column.

Then we create a table and configure the [year & week]’s filter and put the [week] on By value.

 

table 3.jpg

 

The result like this,

 

table 4.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that we have shared?
BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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

11 REPLIES 11
Highlighted
Community Champion
Community Champion

Re: Table with last 4 weeks data

Hi @pedromooji ,

 

You can create a column on your date table and filter the visual based on it.

 

If you consider it as a solution, please mark as a solution and kudos.

Ricardo

 


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

Highlighted
Super User IV
Super User IV

Re: Table with last 4 weeks data

Try like

Measure =
var _max = maxx(allselected('Date'),'Date'[Date])
var _min = _max+-1*WEEKDAY(_max,2)+1 -21 //or -28

return
calculate(Table[Value],filter(all('Date'),'Date'[Date]>=_min && 'Date'[Date]<=_max))



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
My Recent Blog -Week is not so Weak Connect on Linkedin

Proud to be a Super User!

Highlighted
Helper V
Helper V

Re: Table with last 4 weeks data

Hello
It seems to be a good solution, even for months and quarters.
Can you help me on that? I really don't know how....
Thanks in advance

Highlighted
Helper V
Helper V

Re: Table with last 4 weeks data

Hey Amit
Thanks for the answer.
This measure will give me the total for this periode (21 days) and i'd love a total for each week, like my pic.
Is it possible?

Highlighted
Helper II
Helper II

Re: Table with last 4 weeks data

I would first set up a week index in my calendar.  Then I would set up a new column that was "IsLast4Wks" and I would use this column to filter on the visual.  I'm not sure if it is the most efficient way to do it, but I use it for viewing similar based on months.

Highlighted
Helper V
Helper V

Re: Table with last 4 weeks data

Hi @klew31 
Sounds a good idea. Can you share with me how to set those things up, even the way you do it for months?
Very good

Highlighted
Helper II
Helper II

Re: Table with last 4 weeks data

I first set-up my week index like below using a "sort" column.  

 

weekindex.PNG

 

Following that, I have a column for "last3months" as shown below,

 

islast3mths.PNG

I would then put in a filter for "last3months" = yes in the visual.

 

Hope that helps.

 

 

Highlighted
Helper V
Helper V

Re: Table with last 4 weeks data

I'm sorry @klew31  but maybe i did miss something....i don't have any column or measure in my date table named sort.
Can you help?

Highlighted
Helper II
Helper II

Re: Table with last 4 weeks data

Sorry, I am not sure if that is even necessary.  But my calendar date column is "calendardate[date]" and then I have another column called "Sort" which is just,

 

Sort = FORMAT(CalendarDate[Date],"YYYYMM")
 
I believe you have everything now.
 
Like I said, it may not be the most efficient, but I think it will work for you.
 
Good luck.

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors