Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

update visual for previous 6 weeks when a date is selected.

DataSet is called: Calls_TFR

In desktop powerbi, I have a field called WeekEnidng (Ends on a Sunday). An example of the values are as follows.

 

29/10/2023,22/10/2023,15/10/2023,08/10/2023,01/10/2023,24/09/2023,17/09/2023,10/09/2023,03/09/2023,27/08/2023,13/08/2023,06/08/2023,30/07/2023,23/07/2023.

 

Desires result. Have a filter where I can select a date (this will be in a slicer  or filter with the field WeekEnding used) and based on this selection a visual such as a chart or table (which will have WeekEnding and a numerical field called Transfers) which update so that it only displays the last 6 weeks of data.

 

To further clarify if a select the date 29/10/2023, then the visual will be updated for the period 24/09/2023 to 29/10/2023. If I select the date 10/09/2023, then the visual will be updated for the period 06/08/2023 to 10/09/2023

  • Hi Anonymous 
    To achieve your goal you need to add a disconnected table with the weekend days.

    For example with PQ :

    1. create a reference to the fact table

    2. remove all columns except the weekends :

    3. close and apply and if there is a relationship automatically created, remove it:

    4. use a wekkend from new table as a slicer

    5. create a measure for the sum of transfers

    transfers_ = sum('Table'[Transfers])
    6. create a flag measure that will check if the dates of the fact table on visual are in the needed range
    Flag =
     var _days  = 42
    var _selected_date = MAX('weekdays'[WeekEnding])
    return
    IF( MAX('Table'[WeekEnding]) <= _selected_date && MAX('Table'[WeekEnding])>_selected_date -_days ,1,0)
    7. put the data on the visual and use a flag as a filter :

    A file with a solution is attached.

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

3 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Sure, table with out any filters.

      WeekEndingTransfers
      29/10/2023          484,933
      22/10/2023          136,827
      15/10/2023            72,677
      8/10/2023            58,206
      1/10/2023          254,763
      24/09/2023          441,905
      17/09/2023          116,789
      10/09/2023          396,865
      3/09/2023          156,845
      27/08/2023          224,556
      20/08/2023          437,243
      13/08/2023          184,746
      6/08/2023          176,791
      30/07/2023          470,369
      23/07/2023          199,365
      16/07/2023          269,839
      9/07/2023          239,575
      Total       4,322,294

       

      I then have a filter which will have WeekEnding and if I select 29/10/2023 then the table updates to the below:

      WeekEndingTransfers
      29/10/2023     484,933
      22/10/2023     136,827
      15/10/2023       72,677
      8/10/2023       58,206
      1/10/2023     254,763
      24/09/2023     441,905
      Total  1,449,311
      • Ritaf1983's avatar
        Ritaf1983
        Icon for Super User rankSuper User

        Hi Anonymous 
        To achieve your goal you need to add a disconnected table with the weekend days.

        For example with PQ :

        1. create a reference to the fact table

        2. remove all columns except the weekends :

        3. close and apply and if there is a relationship automatically created, remove it:

        4. use a wekkend from new table as a slicer

        5. create a measure for the sum of transfers

        transfers_ = sum('Table'[Transfers])
        6. create a flag measure that will check if the dates of the fact table on visual are in the needed range
        Flag =
         var _days  = 42
        var _selected_date = MAX('weekdays'[WeekEnding])
        return
        IF( MAX('Table'[WeekEnding]) <= _selected_date && MAX('Table'[WeekEnding])>_selected_date -_days ,1,0)
        7. put the data on the visual and use a flag as a filter :

        A file with a solution is attached.

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