Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi guys, thanks for your help.
I have a record of transactions: people accessing software and the date on which they accessed it. On a separate table, I have "contracts." This table includes the company name, software name, and the start and end date of the product's contract. I need to be able to match these individual transactions to which contract they belong to so I can do other transformations. Basically, I'm looking to create a custom column in the transaction table that gives the index number of the contract. This is, in effect, to account for the fact that the transaction records have no link to the contracts. x.x
In order to find out which contract the transaction belongs to, I need to look at the transaction's company name, software name, and the date of the transaction. I want to look up the contracts table and return the index number of the contract that has a matching company name, software name, and... fits within the contract period. That's been tricky.
So for example, John Smith from Cool Company used Software A on 12/4/2022. I'd like to lookup the contracts, see which contract matches "Cool Company," Software A, and the right start and end date (say it was the contract from 3/1/2022-3/1/2023), and return that index number.
At first, I thought I might have to merge these tables, but the records are completely different, and as far as I know, I can't merge them properly since I don't think I can merge them into the correct contract period. Like, it would just go into any random record, not the one with the correct contract start and end date. I don't see an option to merge with some kind of formula.
I didn't realize at first that there's both DAX and Power Query going on in Power BI, so I had posted a request for help with the DAX. Someone responded with the below, so maybe there's a way to transform this into M query? I haven't had much luck so far.
Thanks!
Calc column on Transations:
Solved! Go to Solution.
Hi, @ChelseaCL
a quick conversion from gpt
go to add a custom column then paste this code below. Please adjust the Previous step name first. Or it will show error.
= Table.AddColumn(#"PreviousStepName", "Contract Index", each
let
_startdate = List.First(
Table.Column(
Table.SelectRows(Contracts,
each [Company] = [Company] and [Software] = [Software]
), "Start Date"
)
),
_enddate = List.First(
Table.Column(
Table.SelectRows(Contracts,
each [Company] = [Company] and [Software] = [Software]
), "End Date"
)
),
_indates = [Accessed] >= _startdate and [Accessed] <= _enddate,
_indexnumber = List.First(
Table.Column(
Table.SelectRows(Contracts,
each [Company] = [Company] and [Software] = [Software]
), "Index Number"
)
)
in
if _indates then _indexnumber else null
)
Proud to be a Super User!
Thanks, didn't realize chat gpt was so sophisticated! Still working out various kinks, but this was a great starting point.
Hi, @ChelseaCL
a quick conversion from gpt
go to add a custom column then paste this code below. Please adjust the Previous step name first. Or it will show error.
= Table.AddColumn(#"PreviousStepName", "Contract Index", each
let
_startdate = List.First(
Table.Column(
Table.SelectRows(Contracts,
each [Company] = [Company] and [Software] = [Software]
), "Start Date"
)
),
_enddate = List.First(
Table.Column(
Table.SelectRows(Contracts,
each [Company] = [Company] and [Software] = [Software]
), "End Date"
)
),
_indates = [Accessed] >= _startdate and [Accessed] <= _enddate,
_indexnumber = List.First(
Table.Column(
Table.SelectRows(Contracts,
each [Company] = [Company] and [Software] = [Software]
), "Index Number"
)
)
in
if _indates then _indexnumber else null
)
Proud to be a Super User!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.