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
Anonymous
Not applicable

Show Last 4 Weeks Line Graph Based on Week Slicer

Hi All

I have a line Chart As below and I have Week Number and Year Slicer on my page

 

ajay_g_0-1656428656154.png


At the moment the chart below is only being sliced by my Year Slicer so I can see all the weeks of the selected year

How would I go about changing the chart so it only showed 4 Weeks of data on the X Axis based on the Week Selection of the Week Slicer as the Max week and then go back 3 weeks?

Hope that is clear

Thanks in advance for your help or pointers!

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

I have simulated some data, you can try the following methods.

Week = WEEKNUM([Date])

vzhangti_0-1656676889919.png

Measure = 
Var N1=CALCULATE(MAX('Table'[Week]),ALLSELECTED('Table'[Week]))
Var N2=CALCULATE(MAX('Table'[Week]),ALLSELECTED('Table'[Week]))-3
return
IF(SELECTEDVALUE('Table'[Week])>=N2&&SELECTEDVALUE('Table'[Week])<=N1,1,0)

Put measure into Filter and set it to equal 1.

vzhangti_1-1656676978164.pngvzhangti_2-1656676990446.png

Is this the result you expect? Only the largest 4 weeks are shown.

 

Best Regards,

Community Support Team _Charlotte

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

2 REPLIES 2
v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

I have simulated some data, you can try the following methods.

Week = WEEKNUM([Date])

vzhangti_0-1656676889919.png

Measure = 
Var N1=CALCULATE(MAX('Table'[Week]),ALLSELECTED('Table'[Week]))
Var N2=CALCULATE(MAX('Table'[Week]),ALLSELECTED('Table'[Week]))-3
return
IF(SELECTEDVALUE('Table'[Week])>=N2&&SELECTEDVALUE('Table'[Week])<=N1,1,0)

Put measure into Filter and set it to equal 1.

vzhangti_1-1656676978164.pngvzhangti_2-1656676990446.png

Is this the result you expect? Only the largest 4 weeks are shown.

 

Best Regards,

Community Support Team _Charlotte

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

 

amitchandak
Super User
Super User

@Anonymous , For that you need an independent date/week table. then you can have more weeks

 

Have Week Rank column in both connected and disconnected table 

Week Rank= RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format 

 

//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Week Rank])
var _min = _max -4
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Week Rank] >=_min && 'Date'[Week Rank] <=_max))

 

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

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.