cancel
Showing results for
Did you mean:
Frequent Visitor

## Get value at earliest occurence date

Hi All,

I have a two tables with data as shown below

I wish to write a function that will return the value from the first table where the date is an exact match or the last occurence before dateOn. For instance CAM1 at dateOn 02/01/2011 would return value 43 and CAM6 at dateOn 05/01/2011 would return value 437

Any help is greatly appreciated. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Super Contributor

## Re: Get value at earliest occurence date

Could you show me the screenshot?Please check the formula <=.Please make sure there's no relationship between the two tables.

```Column =
CALCULATE (
SUM ( 'First Table'[values] ),
TOPN (
1,
FILTER (
'First Table',
'First Table'[filed_name] = 'Second Table'[f_name]
&& 'First Table'[date] <= 'Second Table'[dateOn]
),
'First Table'[date], DESC
)
)```

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 REPLIES 4
Super Contributor

## Re: Get value at earliest occurence date

You may try below calculated column.

```Column =
CALCULATE (
SUM ( 'First Table'[values] ),
TOPN (
1,
FILTER (
'First Table',
'First Table'[filed_name] = 'Second Table'[f_name]
&& 'First Table'[date] <= 'Second Table'[dateOn]
),
'First Table'[date], DESC
)
)
```

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Frequent Visitor

## Re: Get value at earliest occurence date

Somehow, the calculated colum returns just the values where the dates is an exact match.

Typed the formula exactly. Don't know if am missing something.

Super Contributor

## Re: Get value at earliest occurence date

Could you show me the screenshot?Please check the formula <=.Please make sure there's no relationship between the two tables.

```Column =
CALCULATE (
SUM ( 'First Table'[values] ),
TOPN (
1,
FILTER (
'First Table',
'First Table'[filed_name] = 'Second Table'[f_name]
&& 'First Table'[date] <= 'Second Table'[dateOn]
),
'First Table'[date], DESC
)
)```

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Frequent Visitor

## Re: Get value at earliest occurence date

There was a relationship between the tables.

Thanks, it works like a charm

Regards

Announcements

#### Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

#### Community News & Announcements

Get your latest community news and announcements.

#### Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

#### Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Top Kudoed Authors
Users Online
Currently online: 262 members 2,873 guests
Recent signins: