Forum Discussion
Power BI Date Range Lookup
I have below two tables.
I need to lookup on my date range table and fetch the Interest rate if the business date lies between the from date and to date.
The expected output looks like below.
I did the research and came across below issue.
https://community.powerbi.com/t5/Desktop/DATE-RANGE-LOOKUP/td-p/420514
But, the formula given in this post throws me an error "A table of multiple values was supplied where a single value was expected"
Formula :
Generally I do something like:
Interest Rate Column = VAR __Date = 'Table1'[Business Date] VAR __ID = 'Table1'[Loan ID] VAR __Rate = MAXX( FILTER( ALL('Table2'), 'Table2'[Loan ID] = __ID && 'Table2'[From Date] <= __Date && 'Table2'[To Date] >= __Date ), [Interest Rate] ) RETURN __Rate
20 Replies
- az38Community Champion
Hi Anonymous
try
test_roi = CALCULATE( FIRSTNONBLANK((test_lms_loan_roi[eff_rate]), 1), FILTER(ALL(test_lms_loan_roi), SELECTEDVALUE(lms_dailybalance_cashflow[Business Date]) >= test_lms_loan_roi[eff_fromdate] && SELECTEDVALUE(lms_dailybalance_cashflow[Business Date]) <= test_lms_loan_roi[eff_todate] && test_lms_loan_roi[mg_intcomp] = 158) ) - AnonymousNot applicable
Hi,
Try using below DAX by creating a new column in Table 1.
Interest Rate = CALCULATE(FIRSTNONBLANK('Table 2'[Interest Rate],1),FILTER(ALL('Table 2'), (AND('Table 1'[Business Date]>'Table 2'[From Date],'Table 1'[Business Date]<'Table 2'[To Date]))))- AnonymousNot applicable
Hi Anonymous this formula is giving all 0.
- Greg_DecklerCommunity Champion
Generally I do something like:
Interest Rate Column = VAR __Date = 'Table1'[Business Date] VAR __ID = 'Table1'[Loan ID] VAR __Rate = MAXX( FILTER( ALL('Table2'), 'Table2'[Loan ID] = __ID && 'Table2'[From Date] <= __Date && 'Table2'[To Date] >= __Date ), [Interest Rate] ) RETURN __Rate- AnonymousNot applicable
- Greg_DecklerCommunity Champion
Great! I didn't test that code so that's good to know!! 🙂
- JuliePFrequent Visitor
I am super new to PowerBI and I think I have a similar query as stated in this thread. I am trying to map the solution to fit my requirements but it is just resulting to a blank cell in power query.
I have a specific date and I want to look this up to return a value against two dates.
Table 1: I am trying to find the value of Term Code from Table 2 that is between the Term End Date and the End Date Threshold:
Table 2:
I was able to achieve this in excel by using the formula: XLOOKUP(C1,$K$2:K5,$M$2:M5,"",-1,1) and i want to replicate this is powerquery:
Resulting Table:
This Question may be elementary but I have been trying to work this out for a while now through google search and youtube videos to no avail.
Thanks.
- Greg_DecklerCommunity Champion
- AnonymousNot applicable
Anonymous : I tried it on PBI Desktop and it is giving the required result.
- AnonymousNot applicable
Thank you Anonymous for investing time in my issue, Probably I have some data issue due to which your formula is not working for me.