Forum Discussion

sivasrao's avatar
sivasrao
Helper III
3 years ago
Solved

Compare two date columns from different tables

Hi,

I have 2 different tables(Table1 and Table2) having the same column names.

In Table 1, we have the Date column and corresponding Week column of the particular date.

Table 2 also same Date Column and here we have to find the week of the date.

 

My requirement is: 

The logic behind the "Compare two date columns, when both dates are equal then the corresponding week(Table1) value is copied into the table 2 week column".

 

     Table 1
DateWeek 
  

 

     Table 2
DateWeek 
  

 

Thank you in advance.

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi sivasrao ,

    Please try below steps:

    1. below is my test table

    Table1:

    Table2:

    2. create a measure with below dax formula

    Week2 =
    VAR cur_date =
        SELECTEDVALUE ( Table2[Date] )
    RETURN
        CALCULATE (
            MAX ( Table1[Week] ),
            FILTER ( ALL ( Table1 ), Table1[Date] = cur_date )
        )
    

    3. add table visual with fields and measure

    Please refer the attached .pbix file.

     

    Best regards,
    Community Support Team_Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi sivasrao ,

    Please try below steps:

    1. below is my test table

    Table1:

    Table2:

    2. create a measure with below dax formula

    Week2 =
    VAR cur_date =
        SELECTEDVALUE ( Table2[Date] )
    RETURN
        CALCULATE (
            MAX ( Table1[Week] ),
            FILTER ( ALL ( Table1 ), Table1[Date] = cur_date )
        )
    

    3. add table visual with fields and measure

    Please refer the attached .pbix file.

     

    Best regards,
    Community Support Team_Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • sivasrao's avatar
      sivasrao
      Helper III

      Thank you for your quick reply.

      I have created a new column with this function and executed it successfully.

       

      CALCULATE (
              MAX ( Table1[Week] ),
              FILTER ( ALL ( Table1 ), Table1[Date] = cur_date )

       

      Thank you.