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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
slatka11
Helper I
Helper I

Lookup value if date falls between 2 dates

I have the two below tables, one with invoice dates and the other with exchange rate date ranges, which I am trying to lookup the exchange rate based on if the invoice date falls within a date range:

 

TABLE 1

Invoice Date
11/17/2022
12/16/2022
12/17/2022
12/18/2022
1/3/2023

 

TABLE 2

EXCH Start DateEXCH End DateEXCH Rate
10/1/202210/31/20221.28
11/1/202211/30/20221.29
12/1/202212/31/20221.3
1/1/20231/31/20231.31
2/1/20232/28/20231.32

 

How would I write a column or measure to lookup the exchange rate based on the invoice date? Thank you.

1 ACCEPTED SOLUTION

Hi @slatka11 

Sorry, there are some misconderations.  Now this:

1) create a measure with this:

 

Rate = 
VAR _date = MAX(Table1[InvoiceDate])
RETURN
MINX(
    FILTER(
        Table2,
        Table2[StartDate]<=_date
             && Table2[EndDate]>=_date
     ),
Table2[ExchRate]
)

 

2) plot a table with the measure and the [InvoiceDate] column. 

 

I tried and it worked like this:

FreemanZ_0-1671240482283.png

View solution in original post

6 REPLIES 6
Salva
Frequent Visitor

Hi,

 

I'm trying to create a DAX formula that looks up a value from table 2 (xyz table), based on conditions from table 1 (abc table). I need the date from table 1 to be inbetween the start date column and end date column from table 2. Below is the formula I've tried to use:

 

Column = LOOKUPVALUE(
    abc[sale],
    abc[Network], xyz[Network],
    abc[Country], xyz[Country],
    abc[Start Date], xyz[Date]
abc[End Date] >= xyz[Date] )

I keep getting an error message because DAX isn't excepting ">=" expression on the last condition. Readng into to "," always means less than or equal to ("<="), what symbol can I use in this formula for great than or equal to (">=").

Hi,

Write this calculated column formula in the abc table

=calculate(sum(xyz[sale]),filter(xyz,xyz[Network]=earlier(abc[Network])&&xyz[Country]=earlier(abc[Country])&&xyz[Start Date]<=earlier(abc[Date])&&xyz[End Date]>=earlier(abc[Date])))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Ashish_Mathur
Super User
Super User

Hi,

Create this calculated column formula in Table 1.

Exchange rate = calculate(sum('Table 2'[EXCH rate]),filter('Table 2','Table 2'[Exch Start Date]<=earlier('Table 1'[Invoice date])&&'Table 2'[Exch End Date]<=earlier('Table 1'[Invoice date])))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
FreemanZ
Super User
Super User

hi @slatka11 

Try to add a column in Table1 with this:
Rate =
VAR _date = [InvoiceDate]
RETURN
MINX(
    FILTER(
        Table2,
        Table2[StartDate]<=_date
             && Table2[EndDate]>=_date)
     ),
Table2[ExchRate]
)

hi @FreemanZ

 

I get to the last part of the formula where you have Table2[ExchRate] but when I try to save the formula I get an error "The syntax for ',' is incorrect

 

Am I doing something wrong? When I start typing the last part (Table2[ExchRate]) it appears as grey text

Hi @slatka11 

Sorry, there are some misconderations.  Now this:

1) create a measure with this:

 

Rate = 
VAR _date = MAX(Table1[InvoiceDate])
RETURN
MINX(
    FILTER(
        Table2,
        Table2[StartDate]<=_date
             && Table2[EndDate]>=_date
     ),
Table2[ExchRate]
)

 

2) plot a table with the measure and the [InvoiceDate] column. 

 

I tried and it worked like this:

FreemanZ_0-1671240482283.png

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors