Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
gauravnarchal
Post Prodigy
Post Prodigy

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
1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@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])

1.PNG

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
ryan_mayu
Super User
Super User

@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])

1.PNG

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Samarth_18
Community Champion
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:-

Samarth_18_0-1628168315531.png

 

Thanks,

Samarth

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors