cancel
Showing results for
Did you mean:

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

New Member

## Asking for help with a Dates Calculated Column

I'm still a pretty new BI user, coming from years of excel experience, so I'm still trying to learn the DAX/excel formula crossover.

I have a dataset of transaction dates, pulling invoice and receipt data, identified by the TransType of IN (invoice) and CR (cash receipt). I'm wanting to create a calculated column that shows me the invoice date, because my data set ONLY has the transaction date.

What I would expect in excel would be an IF formula with a nested INDEX to lookup the transaction date of the Invoice line: "IF(TransType = "IN",TransDate,INDEX(TransDate,MATCH(invoice218978,Invoice,0))). Not having the Index-Match option in BI is hurting me. Basically what I'm wanting is, if the transaction is "IN", make the calculated column InvDate equal the TransDate of that line. If it's a "CR" transaction, lookup the invoice number from within the dataset and pull back the TransDate from the corresponding "IN" transaction.

Here's an example of the dataset that I have:

 TransactionType TransactionDate TransactionAmount InvoiceNumber INVDATE IN 2/10/2022 4025 218978 =inv218978 TransType IN TransDate CR 4/18/2022 4025 218978 =inv218978 TransType IN TransDate IN 2/15/2022 1926 219105 =inv219105 TransType IN TransDate IN 2/15/2022 6854 219106 =inv219106 TransType IN TransDate CR 4/19/2022 1926 219105 =inv219105 TransType IN TransDate

Any insight on this, even if it's to tell me I'm way off would be extremely appreciated!

1 ACCEPTED SOLUTION
Community Support

Hi @vandelD ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can create a calculated column as below:

``````INVDATE =
CALCULATE (
MAX ( 'Table'[TransactionDate] ),
FILTER (
'Table',
'Table'[InvoiceNumber] = EARLIER ( 'Table'[InvoiceNumber] )
&& 'Table'[TransactionType] = "IN"
)
)``````

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
5 REPLIES 5
Community Support

Hi @vandelD ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can create a calculated column as below:

``````INVDATE =
CALCULATE (
MAX ( 'Table'[TransactionDate] ),
FILTER (
'Table',
'Table'[InvoiceNumber] = EARLIER ( 'Table'[InvoiceNumber] )
&& 'Table'[TransactionType] = "IN"
)
)``````

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
New Member

This seems to work, thank you so much for the help!

Super User
``````InvDate = IF( 'Table'[Transaction Type] = "IN", 'Table'[Transaction Date],
var invNumber = 'Table'[Invoice Number]
return LOOKUPVALUE( 'Table'[Transaction Date], 'Table'[Invoice Number], invNumber, 'Table'[Transaction Type], "IN")
)``````
New Member

Thanks for the feedback, johnt75, I think this got me very close. I got an error that multiple values were returned where a single value was expected. I'm thinking this is due to the fact that a single invoice number can show appear mutliple times in the dataset if there were multiple lines invoiced. Any suggestions for working around the duplicates? Thanks!

Super User

you could try wrapping the LOOKUPVALUE in DISTINCT()

Announcements

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

#### Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

#### Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors