Forum Discussion

Yasser92's avatar
Yasser92
Frequent Visitor
8 years ago
Solved

Complicated case

Hi everyone, 

 

I have two tables, and I'm looking for matching Table1's rows with table2's rows like I'm showing on the table below 

 

Table1: 

Order NLine NDelivery Date
L12115/01/2017
L12717/02/2017
L13102/03/2017
L14220/03/2017
L15419/05/2017
L15501/02/2017
L14301/02/2017
L20108/08/2017

 

Table2 :

 

Order NLine NExpected DelivDate
L12121/08/2017
L12722/08/2017
L13123/08/2017
L14324/08/2017
L11225/08/2017
L154 
L15524/08/2017
L14524/08/2017
L12 
L21201/08/2017
L301 
L12124/08/2017

 

 

Result :

 

Order NLine NDelivery DateExpected DelivDate
L12115/01/201724/08/2017
L12717/02/201722/08/2017
L13102/03/201723/08/2017
L14220/03/2017 
L15419/05/2017 
L15501/02/201724/08/2017
L14301/02/201724/08/2017
L20108/08/2017 



I used this code as a solution: 
TableResult = SUMMARIZE(
GENERATE(
Table1; Var OrderNum = 'Table1'[Order N]
Var LineNum = 'Table2'[Line N]
return FILTER('Table2'; 'Table2'[Order N]=OrderNum && 'Table2'[Line N]=LineNum )
);
Table2[Order N]; Table2[Line N];
"Delivery Date"; MAX(Table2[Expected DelivDate])
)

 

But that doesn't really work.

 

Someone can help me please.

  • does it have to be single formula?
    why can't you add a calculated column with Expected Delivery Date to Table1?

    Also - are you creating this table to calculate time difference only? if so this should be possible to achieve with a measure, without creating a new table

    EDIT - this calculated formula witll work when added to Table1

    Expected Delivery Date= 
    VAR CurrentOrder = Table1[Order N]
    VAR CurrentLine = Table1[Line N]
    RETURN
    CALCULATE(MAX(Table2[Expected DelivDate]),Table2[Order N]=CurrentOrder,Table2[Line N]=CurrentLine)

2 Replies

  • Stachu's avatar
    Stachu
    Community Champion

    does it have to be single formula?
    why can't you add a calculated column with Expected Delivery Date to Table1?

    Also - are you creating this table to calculate time difference only? if so this should be possible to achieve with a measure, without creating a new table

    EDIT - this calculated formula witll work when added to Table1

    Expected Delivery Date= 
    VAR CurrentOrder = Table1[Order N]
    VAR CurrentLine = Table1[Line N]
    RETURN
    CALCULATE(MAX(Table2[Expected DelivDate]),Table2[Order N]=CurrentOrder,Table2[Line N]=CurrentLine)
    • Yasser92's avatar
      Yasser92
      Frequent Visitor

      Thank you a lot for the response; 

       

      It's more useful for my case; 

       

      And you are right, I want to make some measures, but not directly on the Expected Delivery date and the Delivery date. I should create two other columns : 

      Column1 = If(Delivery Date - Expected DelivDate >7;0;1)

      Calumn2= If(Delivery Date - Estimate DelivDate>7;0;1)

       

      Estimate DelivDate is estimated by our Service and the expected DelivDate is estimated by our supplier.

       

      After that, I'll add a third column which is the max (Column1;Column2) and calculate the percentage of the sum(Calumn3)Divided by count(Orders).