Forum Discussion

MaxTrumblay's avatar
MaxTrumblay
Frequent Visitor
9 years ago
Solved

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 

7 Replies

  • Phil_Seamark's avatar
    Phil_Seamark
    Microsoft Employee

    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/guestaccess.aspx?docid=04d5ac12c227a45ef9c60b5a5e94c4c30&authkey=AUWLcaZAY4GcFtYzWn--dEk

     

     

     

    • MaxTrumblay's avatar
      MaxTrumblay
      Frequent Visitor

      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

      • Phil_Seamark's avatar
        Phil_Seamark
        Microsoft Employee
        You can have more than one calendar table. Did you try my PBIX file?
    • Aasish's avatar
      Aasish
      Frequent Visitor

      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 :

      Can you please help me on this ? 

  • 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?