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
waseem_24
Frequent Visitor

Selected week and Last 4 Weeks Data Based on Selected Week

Hello Everyone,

 

I have a requirement where in I have to display the selected week data and last 3 weeks data in a bar chart.

Week slicer contains the values in format 

waseem_24_0-1610395111864.png

The required output look like this. If suppose I have selected 27 Nov-3 Dec, then the graph should look like this.

waseem_24_1-1610395306717.png

I have made few measures like 

Week Avg Prev Week  =
CALCULATE([AA_Week Avg],
FILTER(ALL('Dates Mapping'),
'Dates Mapping'[Index Week] = SELECTEDVALUE('Dates Mapping'[Index Week])-1 &&
'Dates Mapping'[YEAR] = SELECTEDVALUE('Dates Mapping'[YEAR])))
 
AA_Week Avg Prev 2 =
CALCULATE([AA_Week Avg],
FILTER(ALL('Dates Mapping'),
'Dates Mapping'[Index Week] = SELECTEDVALUE('Dates Mapping'[Index Week])-2 &&
'Dates Mapping'[YEAR] = SELECTEDVALUE('Dates Mapping'[YEAR])))
 
But I am unable to achieve the required output, Can anyone please help me resolve this issue.
 
 
 
Thanks.
waseem

 

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

Hi @waseem_24 ,

 

I have used the following formula to reproduce a data sample:

Table =
ADDCOLUMNS (
    CALENDAR ( "2020/1/1", "2020/12/31" ),
    "Week Number", WEEKNUM ( [Date], 2 )
)

1.14.2.1.PNG

 

In order to create dynamical chart, I extracted the Week Number and Week columns to a new table for slicer, and clicked the Sort by column tab to sort the Week column by Week Number column like this:

ForSlicer =
DISTINCT (
    SELECTCOLUMNS ( 'Table', "Week", [Week], "Week Number", [Week Number] )
)

1.14.2.2.jpg

 

Moving forword, created a measure and applied it to filter pane:

Measure =
VAR _sele =
    SELECTEDVALUE ( ForSlicer[Week] )
VAR _weekNum =
    MINX ( FILTER ( ALL ( 'Table' ), 'Table'[Week] = _sele ), [Week Number] )
RETURN
    IF (
        MAX ( 'Table'[Week Number] ) >= _weekNum - 3
            && MAX ( 'Table'[Week Number] ) <= _weekNum,
        1,
        0
    )

 

The final output is shown below:

1.14.2.3.gif

Please kindly take a look at the pbix file here.

 

Best Regards,
Eyelyn Qin
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

8 REPLIES 8
Jyo27
Helper II
Helper II

I have the same issue . Its working for me this solution . But when I clear the selection for week slicer I need all the week data . How can I achieve this?

v-eqin-msft
Community Support
Community Support

Hi @waseem_24 ,

 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it.

Or you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file from your Onedrive for Business after removing sensitive data.

 

Best Regards,
Eyelyn Qin

waseem_24
Frequent Visitor

Thanks @amitchandak  and @v-eqin-msft  I am able to achieve the required output,

But is there a way, where I can use the slicer week from the main date table or the values tables instead of taking it from new table, as I have other charts and tables on the page that should interactive with the slicer.

 

 

Thanks

Waseem

Hi @waseem_24 ,

 

No.

If you use the original column in table for slicer and then for example ,select 10 Feb-16 Feb.

In this case, only date between this range will be displayed. , it is impossible to filter out the values of the previous three weeks which is why we need to create a separate table.

 

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

v-eqin-msft
Community Support
Community Support

Hi @waseem_24 ,

 

I have used the following formula to reproduce a data sample:

Table =
ADDCOLUMNS (
    CALENDAR ( "2020/1/1", "2020/12/31" ),
    "Week Number", WEEKNUM ( [Date], 2 )
)

1.14.2.1.PNG

 

In order to create dynamical chart, I extracted the Week Number and Week columns to a new table for slicer, and clicked the Sort by column tab to sort the Week column by Week Number column like this:

ForSlicer =
DISTINCT (
    SELECTCOLUMNS ( 'Table', "Week", [Week], "Week Number", [Week Number] )
)

1.14.2.2.jpg

 

Moving forword, created a measure and applied it to filter pane:

Measure =
VAR _sele =
    SELECTEDVALUE ( ForSlicer[Week] )
VAR _weekNum =
    MINX ( FILTER ( ALL ( 'Table' ), 'Table'[Week] = _sele ), [Week Number] )
RETURN
    IF (
        MAX ( 'Table'[Week Number] ) >= _weekNum - 3
            && MAX ( 'Table'[Week Number] ) <= _weekNum,
        1,
        0
    )

 

The final output is shown below:

1.14.2.3.gif

Please kindly take a look at the pbix file here.

 

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

Anonymous
Not applicable

Hi @v-eqin-msft ,

 

the sample pbix file is no longer available. Can you please be so kind and upload it again?

 

Regards,

Toddy

 

amitchandak
Super User
Super User

@waseem_24 , relative date slicer is best in all such case, When you can not use you have take help two table, to do it.

Refer to this example - This is for 12 months, but you have to use this for weeks

https://www.youtube.com/watch?v=duMSovyosXE

 

Check if needed

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8

aj1973
Community Champion
Community Champion

Hi @waseem_24 

Your isssue is not exposed wisely! 

what do you want to do with the above measures?

This measure [AA_Week Avg] where is it?

using SLECTEDVALUE! what value you want to select?

Can you share a Sample of your PBIX please, this will help the community understand quicker and better

Thnaks

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

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.