Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

Complex Dates compare

Hello Experts,

Please help me with this date comparison.

I have a dates table with Snapshots Column where we take Snapshots every other Saturday. Sometimes there may be only one snapshot per month.

Ex Dates data comes in one column. 

If the user selects CY date 12/03/2022, they want to see the same metric for LY and LLY.

 

CYLYLLY
12/31/202212/04/202112/05/2020
12/03/202212/04/202112/05/2020
11/12/202211/13/202111/14/2020
10/29/202210/30/202110/31/2020
10/15/202210/30/202110/31/2020
10/01/202210/02/202110/03/2020
09/17/202209/18/2021 
09/03/202209/18/2021 
08/20/202208/28/2021 
07/30/202207/31/2021 
07/16/202207/31/2021 
07/02/202207/03/2021 
06/18/202206/19/2021 
05/28/202205/29/2021 
05/14/202205/01/2021 
04/30/202204/17/2021 
04/16/202204/17/2021 
04/02/202204/03/2021 
03/19/202203/20/2021 
02/26/202202/27/2021 

 

Expercted Output:

 

CY12/03/2022100
LY12/04/2021299
LLY12/05/2020150

 

Thanks.

11 Replies

  • I have some question to it: 
    1) Date is MM/DD/YYYY in your example? 
    2) Are CY,LY,LLY separate columns? Where are the metrics? Do you have a example for it?
    3) If you select one month and there are more snapshot in this month, which one should be selected: all? the last one? 

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi andhiii079845 ,

      Thank you for looking into it.

       

      I have some question to it: 
      1) Date is MM/DD/YYYY in your example?  Yes, Its a date column.
      2) Are CY,LY,LLY separate columns? They all come from one date column. I seperated them by year to explain better.
      Where are the metrics? I added test data (Please see below)
      Date table Key joind to Fact tables

       

      DateSales
      12/31/2022125
      12/03/2022126
      11/12/2022127
      10/29/2022128
      10/15/2022129
      10/01/2022130
      09/17/2022131
      09/03/2022132
      08/20/2022133
      07/30/2022134
      07/16/2022135
      07/02/2022136
      06/18/2022137
      05/28/2022138
      05/14/2022139
      04/30/2022140
      04/16/2022141
      04/02/2022142
      03/19/2022143
      02/26/2022144
      12/04/2021145
      12/04/2021146
      11/13/2021147
      10/30/2021148
      10/30/2021149
      10/02/2021150
      09/18/2021151
      09/18/2021152
      08/28/2021153
      07/31/2021154
      07/31/2021155
      07/03/2021156
      06/19/2021157
      05/29/2021158
      05/01/2021159
      04/17/2021160
      04/17/2021161
      04/03/2021162
      03/20/2021163
      02/27/2021164
      12/05/2020165
      12/05/2020166
      11/14/2020167
      10/31/2020168
      10/31/2020169
      10/03/2020170


      Do you have a example for it? Yes added 

      3) If you select one month and there are more snapshot in this month, which one should be selected: all? the last one?  

      CY12/03/2022126
      LY12/04/2021145
      LLY12/05/2020165

      This is good example.

      They took two snapshots in 2022 , but previous year only one. 

      If users selects 12/31/2022, or 12/03/2022 , the pattern shold be like below.

       

      12/31/202212/04/202112/05/2020
      12/03/202212/04/202112/05/2020

       

      Thanks a lot.

  • The logic is that all snapshot from the LY und LLY in the same (selected) month should be shown? 

    • Anonymous's avatar
      Anonymous
      Not applicable

      andhiii079845 

       

      Yes, That's correct.

       

      All these are examples.

      If they select CY date the patten is like below.

       

      CYLYLLY
      12/31/202212/04/202112/05/2020
      12/03/202212/04/202112/05/2020
      11/12/202211/13/202111/14/2020
      10/29/202210/30/202110/31/2020
      10/15/202210/30/202110/31/2020
      10/01/202210/02/202110/03/2020
      09/17/202209/18/2021 
      09/03/202209/18/2021 
      08/20/202208/28/2021 
      07/30/202207/31/2021 
      07/16/202207/31/2021 
      07/02/202207/03/2021 
      06/18/202206/19/2021 
      05/28/202205/29/2021 
      05/14/202205/01/2021 
      04/30/202204/17/2021 
      04/16/202204/17/2021 
      04/02/202204/03/2021 
      03/19/202203/20/2021 
      02/26/202202/27/2021 

      Thank you.

  • My solution:
    1) First you need a second table "Dimtable" with distinct date values from the other table (Via Power Query Editor: reference table and remove duplicate )

    2) Create a slicer with the Dimtable Date column and matrix with date, sales column from the table "example" 

     

    ā€ƒ

    3) DAX Formular:

    FilterData = 

    VAR _selectmonth2 = MONTH(SELECTEDVALUE(Dimtable[Date]))
    VAR _currentmonth = MONTH(maxx(example,example[Date]))
    VAR  _filter = IF(_currentmonth=_selectmonth2,1,0)

    RETURN _filter
     
    4) Filter the matrix visual with the FilterData Measure (greater than or equal to 1)

     

    I hope this was a good walkthrough. 

    ā€ƒ