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

Based on current week selection in Slicer Previous 6 weeks data display under line/bar chart

I'm Having Year Slicer, In that i have data for Years

e.g

Slicer 1st data as below

2017

2016

and second slicer is for weeks for those years

e.g having below data

Slicer 2nd data as below

02-01-2017

09-01-2017

16-01-2017

23-01-2017

30-01-2017

06-02-2017

13-02-2017

 

15-02-2016

22-02-2016

29-02-2016

07-03-2016

14-03-2016

21-03-2016

28-03-2016

 

Suppose user selects any week from above weeks list in the slicer , In another chart i.e Line or bar chart Previous 6 weeks data will be display means suppose user selected week here is 09-01-2017 then in another chart i.e line\bar data displays upto Previous 6 weeks data

i.e from 16-01-2017 to 15-02-2016 and its is work as dynamic solution. help really appricate and revert if have any solution on that as i'm new in Power BI

1 ACCEPTED SOLUTION
Anonymous
Not applicable
9 REPLIES 9
Eric_Zhang
Employee
Employee

@Anonymous

For this case, I think you need a calendar table as below. And then create a one to many relationship between your table and dim_date.

 

dim_date = 
VAR TBL =
    FILTER (
        ADDCOLUMNS (
            CALENDAR ( "2016-01-01", "2017-12-31" ),
            "WEEKDAY", WEEKDAY ( [Date] )
        ),
        [WEEKDAY] = 7
    )
RETURN
    ADDCOLUMNS ( TBL, "RANK", RANKX ( TBL, [Date],, ASC ) )

Capture.PNG

 

To get the data for last 6 weeks, create a measure like

 

measure =
SUMX (
    FILTER (
        ALL ( yourTable ),
        dim_date[RANK] <= MAX ( dim_date[RANK] )
            && dim_date[RANK]
                >= MAX ( dim_date[RANK] ) - 6
    ),
    [somecolumn]
)

 

 

Anonymous
Not applicable

Coluld you please explain me more this solution so i can used in that in my file.

Anonymous
Not applicable

@Eric_Zhang Thanks to reply on my Post, I'm new in Power BI and DAX coluld you please explain more brifly how its work's when i selectd current year in slicer it returns 6 weeks data under Line chart including current week. Please explain More its helps me.

@Anonymous

I think the solution shall work. Have you tried in your case? If you can post the sample in your case, I can explain the DAX accordingly.

Anonymous
Not applicable

Thanks @Eric_Zhang i tried another Solution and that's works for me . Thanks for your reply and help.

@Anonymous

Could you share your approach and accept it as solution to close this thread? People who have the similar question can benenif from the solution. 🙂 

Anonymous
Not applicable

Hello @Eric_Zhang

 

 

Sorry for delay in reply Actully i was on leave for few days.

 

Hi @Eric_Zhang My Solution works only when there is no any relationship between 2 tables. You can checked in below images i i have selected weeknumbers 12 and in line chart data display from week numbers 12 to week numbers 6. As this soution working Properly.  

 

 

 

Working when there is no relation into two tablesWorking when there is no relation into two tables

 

 but when i have added Datekey into both tables and Datekey here is Index column which makes active relationship into both tables then above solution is not working. i want above scenario working when two tables or more than 2 tables having

relationship between them. 

tables.JPG

 

 As in your solution you have rank column. Guide me on this Approach

 

 

Anonymous
Not applicable

Hi

 

If possible please write dax here for below solution?

Anonymous
Not applicable

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.