Hi @chrisgreenslade,
See if any of these methods meet your requirement. Also it seemed like the signs in your initial logic were switched so I changed that and since the results are static, first a Power Query Solution.
AddPurchDuration = Table.AddColumn(#"Changed Type", "Purchase Duration", each
let
pTerminal = [Terminal ID],
pDayName = [Purchase Start Day Name],
pStartDate = Date.From([#"Purchase Start Date & Time"]),
pStartTime = Number.From(Time.From([#"Purchase Start Date & Time"])),
pAmount = Number.From( Text.Remove( [Purchase Amount], "£")),
rTable = Table.SelectRows( BufferedTariff, (BT)=>
BT[Terminal ID] = pTerminal and
BT[Day Name] = pDayName and
BT[Tariff Start Date] <= pStartDate and
BT[Tariff End Date] >= pStartDate and
BT[Tariff Amount Start] <= pAmount and
BT[Tariff Amount End] >= pAmount and
(( Number.From(BT[Tariff Start Time 1]) * ( 1 / 24 ) <= pStartTime and
Number.From(BT[Tariff End Time 1]) * ( 1 / 24 ) > pStartTime ) or
( Number.From(BT[Tariff Start Time 2]) * ( 1 / 24 ) <= pStartTime and
Number.From(BT[Tariff End Time 2]) * ( 1 / 24 ) > pStartTime ))
)
in if Table.RowCount(rTable) >0 then Text.Combine( List.Transform(rTable[Tariff Duration], each Text.From(_)), ", ") else null
.
But this can also be done in DAX, preferred method is as a Measure.
Purchase Duration Measure =
VAR pTerminal = SELECTEDVALUE(Purchase[Terminal ID])
VAR pDayName = SELECTEDVALUE(Purchase[Purchase Start Day Name])
VAR pStartDate = INT( SELECTEDVALUE(Purchase[Purchase Start Date & Time] ))
VAR pStartTime = MOD( SELECTEDVALUE(Purchase[Purchase Start Date & Time]), 1 )
VAR pAmount = SUBSTITUTE( SELECTEDVALUE( Purchase[Purchase Amount]), "£", "" ) *1
RETURN
CONCATENATEX(
FILTER( Tariff,
Tariff[Terminal ID] = pTerminal &&
Tariff[Day Name] = pDayName &&
Tariff[Tariff Start Date] <= pStartDate &&
Tariff[Tariff End Date] >= pStartDate &&
Tariff[Tariff Amount Start] <= pAmount &&
Tariff[Tariff Amount End] >= pAmount &&
( Tariff[Tariff Start Time 1] * (1/24) <= pStartTime &&
Tariff[Tariff End Time 1] * (1/24) > pStartTime ) ||
( Tariff[Tariff Start Time 2] * (1/24) <= pStartTime &&
Tariff[Tariff End Time 2] * (1/24) > pStartTime )
), Tariff[Tariff Duration], ", "
)
.
and finally least preffered method a Calculated Column in DAX
Purchase Duration CC =
VAR pTerminal = Purchase[Terminal ID]
VAR pDayName = Purchase[Purchase Start Day Name]
VAR pStartDate = INT( Purchase[Purchase Start Date & Time] )
VAR pStartTime = MOD( Purchase[Purchase Start Date & Time], 1 )
VAR pAmount = SUBSTITUTE( Purchase[Purchase Amount], "£", "" ) *1
RETURN
CONCATENATEX(
FILTER( Tariff,
Tariff[Terminal ID] = pTerminal &&
Tariff[Day Name] = pDayName &&
Tariff[Tariff Start Date] <= pStartDate &&
Tariff[Tariff End Date] >= pStartDate &&
Tariff[Tariff Amount Start] <= pAmount &&
Tariff[Tariff Amount End] >= pAmount &&
( Tariff[Tariff Start Time 1] * (1/24) <= pStartTime &&
Tariff[Tariff End Time 1] * (1/24) > pStartTime ) ||
( Tariff[Tariff Start Time 2] * (1/24) <= pStartTime &&
Tariff[Tariff End Time 2] * (1/24) > pStartTime )
), Tariff[Tariff Duration], ", "
)
.
Here’s your sample file. eDNA - Lookup with CONTATENATEX.pbix (102.9 KB)
I hope this is helpful.