cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MaxTrumblay
Frequent Visitor

Display last 4 weeks data based on selected week

 

Hi everyone,

 

So here's my problem, I want to make a graph showing the currently selected week from my filter and the [Week]-1,[Week]-2,[Week]-3.

 

Is there any measure or DAX formula existing to solve my problem?

 

Thanks,

 

Max 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Microsoft Phil_Seamark
Microsoft

Re: Display last 4 weeks data based on selected week

Hi @MaxTrumblay

 

Create a Date table but don't link it to your main data table.  Make sure your new date table has a week starting column that matches your data table.

 

Then simply create this measure on your data table and add it as a filter on your bar chart.

 

Date Range Filter = IF(
			MAX('Table1'[Date]) <= MIN('Dates'[WeekStarting])
			&& MAX('Table1'[Date]) >= MIN('Dates'[WeekStarting])-21
			--------------------------------------------------------
			, 1 , 0)

Here is a link to a PBIX file so you can see it working

 

https://wgtnpowerbi-my.sharepoint.com/personal/phil_wgtnpowerbi_onmicrosoft_com/_layouts/15/guestacc...

 

 

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

6 REPLIES 6
Highlighted
Microsoft Phil_Seamark
Microsoft

Re: Display last 4 weeks data based on selected week

Hi @MaxTrumblay

 

Create a Date table but don't link it to your main data table.  Make sure your new date table has a week starting column that matches your data table.

 

Then simply create this measure on your data table and add it as a filter on your bar chart.

 

Date Range Filter = IF(
			MAX('Table1'[Date]) <= MIN('Dates'[WeekStarting])
			&& MAX('Table1'[Date]) >= MIN('Dates'[WeekStarting])-21
			--------------------------------------------------------
			, 1 , 0)

Here is a link to a PBIX file so you can see it working

 

https://wgtnpowerbi-my.sharepoint.com/personal/phil_wgtnpowerbi_onmicrosoft_com/_layouts/15/guestacc...

 

 

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

MaxTrumblay
Frequent Visitor

Re: Display last 4 weeks data based on selected week

Thanks a lot @Phil_Seamark for the fast reply. It's not working but I am assuming it because the interaction of my calendar and my database are not correctly done. I think I need to solve that issue by rethinking the way the database will be populated then it will work properly.

 

Best regards,

 

Max

Microsoft Phil_Seamark
Microsoft

Re: Display last 4 weeks data based on selected week

You can have more than one calendar table. Did you try my PBIX file?

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

MaxTrumblay
Frequent Visitor

Re: Display last 4 weeks data based on selected week

Hi @Phil_Seamark,

Yes, I tried it. I understand the logic, unfortunately, I'm not able to replicate it for my situation. Probably only an interaction problem. my METRICS table (table1 in your case) is using DateID and is linked to my DATE table with a DateID. I don't know how I can use a new date table and make it work only using one filter (from my DATE table).

 

Thanks in advance,

Max 

Microsoft Phil_Seamark
Microsoft

Re: Display last 4 weeks data based on selected week

I think the key is to not use your existing date table.

 

I'd suggest using a different table to your main Date table (you can have more than one)

 

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Aasish
Frequent Visitor

Re: Display last 4 weeks data based on selected week

Hi @Phil_Seamark 

 

I tried your formula, but i have something modified according to my need i have replaced the weekstartingdate to weekendingdate and the formula is wroking perfectly fine showing me the 3 weeks after the date which i select. But this is working only in bar or line chart level but its not working with the matrix table. When i bring the week end column into column field my matrix table goes blank. I am trying to achive something like below :Capture.PNG

Can you please help me on this ? 

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

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

Top Solution Authors