Forum Discussion

gauravnarchal's avatar
gauravnarchal
Post Prodigy
5 years ago
Solved

Need help with Calculated Column

Hi

 

I want to create a calculated column to find the days between two dates as below

 

If the invoice number starts with 9 then onward (Minus) - return else return (Minus) - onward

 

Date - Table 1

 

Invoice IDInvoice No
9192391IG
9192401DEFAUL
919241190989800
9192421DEFAUL/
9192431DEFAUL:
9192441DEFAUL/DEL
91924511574 11
9192461DEFAUL;
919247180987897
91924819090985
91929818088452
91934818088717

 

Date - Table 2

 

Invoice IDOnwardReturn
919239110-Aug-2119-Aug-21
919240120-Aug-2128-Aug-21
919241130-Aug-219-Sep-21
91924219-Sep-2120-Sep-21
919243119-Sep-2124-Sep-21
919244129-Sep-211-Oct-21
91924519-Oct-2110-Oct-21
919246119-Oct-2131-Oct-21
919247129-Oct-217-Nov-21
91924818-Nov-2118-Nov-21
919298110-Sep-2110-Sep-21
919348112-Sep-2111-Sep-21

 

Result

 

Invoice IDOnwardReturnResult
919239110-Aug-2119-Aug-219
919240120-Aug-2128-Aug-218
919241130-Aug-219-Sep-21-10
91924219-Sep-2120-Sep-2111
919243119-Sep-2124-Sep-215
919244129-Sep-211-Oct-212
91924519-Oct-2110-Oct-211
919246119-Oct-2131-Oct-2112
919247129-Oct-217-Nov-219
91924818-Nov-2118-Nov-21-10
919298110-Sep-2110-Sep-210
919348112-Sep-2111-Sep-21-1
  Total37
  • gauravnarchal 

    if there is a relationship between two tables, you can try this

    Column = if(LEFT(RELATED(Table1[Invoice No]),1)="9",Table2[Onward]-Table2[Return],Table2[Return]-Table2[Onward])

    pls see the attachment below

2 Replies

  • Samarth_18's avatar
    Samarth_18
    Community Champion

    Hi gauravnarchal 

     

    You can create a lookup column in your table 2 with below code to bring invoice number in this table:-

     

    Invoice_No =
    LOOKUPVALUE (
        'Date - Table 1'[Invoice No],
        'Date - Table 1'[Invoice ID], 'Date - Table 2'[Invoice ID]
    )

     

    Now you can create your required column with below code:-

     

    Date_Diff =
    VAR ifnine =
        LEFT ( 'Date - Table 2'[Invoice_No], 1 )
    RETURN
        IF (
            ifnine = "9",
            DATEDIFF ( 'Date - Table 2'[Return], 'Date - Table 2'[Onward], DAY ),
            DATEDIFF ( 'Date - Table 2'[Onward], 'Date - Table 2'[Return], DAY )
        )

     

    Output:-

     

    Thanks,

    Samarth

     

  • gauravnarchal 

    if there is a relationship between two tables, you can try this

    Column = if(LEFT(RELATED(Table1[Invoice No]),1)="9",Table2[Onward]-Table2[Return],Table2[Return]-Table2[Onward])

    pls see the attachment below