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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Eswar
Regular Visitor

field corresponding Date from another table earlier than selected date in different table

Hi,
I have two tables as below. I want a calculated column displaying the visit field in Table 2 based on date condition.
Condition: The Table1 (date) eariler than the Table2 (Date) by name. Please help me.

Table 1

NameVisitDate
AW11-Jan-25
AW210-Jan-25
AW317-Jan-25
BW13-Jan-25
BW28-Jan-25
BW315-Jan-25
CW19-Jan-25
CW216-Jan-25
CW325-Jan-25

Table 2

NameEvent
A15-Jan-25
B7-Jan-25
C30-Jan-25

Output with calculated column in Table 2 is expected as

NameEventCalculated column
A15-Jan-25W2
B7-Jan-25W1
C30-Jan-25W3
8 REPLIES 8
Anonymous
Not applicable

Hi @Eswar ,
we haven't heard back from you regarding our last response and wanted to check if your issue has been resolved.
If our response addressed your query, please mark it as Accept Answer and click Yes if you found it helpful.
If you have any further questions, feel free to reach out.
Thank you for being a part of the Microsoft Fabric Community Forum!

Anonymous
Not applicable

Hi Eswar ,
May I ask of your issue has been resolved.If so,kindly share the solution or mark the answer that helped you.It will be halpful for the others in the community who may face similar issue.If not ,please follow with the below steps:
Please try this DAX for the calculated column in Table2:


CalculatedColumn =
VAR CurrentName = Table2[Name]
VAR CurrentEventDate = Table2[Event]
RETURN
MAXX(
TOPN(
1,
FILTER(
Table1,
Table1[Name] = CurrentName &&
Table1[Date] < CurrentEventDate
),
Table1[Date], DESC
),
Table1[Visit]
)



Thank you.

Anonymous
Not applicable

Hi @Eswar ,
Thank you @FarhanJeelani  and @bhanu_gautam for the helpful insights!
Could you please confirm if the issue has been resolved on your end? If a solution has been found, it would be greatly appreciated if you could share your insights with the community. This would be helpful for other members who may encounter similar issues.
Thank you for your understanding and assistance.

Regards,
Pallavi.

bhanu_gautam
Super User
Super User

@Eswar Create a calculated column in Table 2 using the following DAX formula:

dax
CalculatedColumn =
VAR CurrentName = Table2[Name]
VAR CurrentEventDate = Table2[Event]
RETURN
MAXX(
FILTER(
Table1,
Table1[Name] = CurrentName && Table1[Date] < CurrentEventDate
),
Table1[Visit]
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Hi Bhanu, Thank you. I asked a partial question. In the Table 2, if multiple records by the same name. 

Table1 Remains same.
Table 2

NameRecordPositionEvent
A115-Jan-25
B17-Jan-25
C130-Jan-25
A29-Jan-25
A323-Jan-25
B214-Jan-25
B313-Jan-25
C210-jan-25
C318-Jan-25

The output expected is 

NameRecordPositionEventCalculated column
A115-Jan-25W2
B17-Jan-25W1
C130-Jan-25W3
A29-Jan-25W1
A323-Jan-25W3
B217-Jan-25W3
B313-Jan-25W1
C210-jan-25W1
C318-Jan-25W2

Hi @Eswar ,

To handle multiple records for the same name in Table 2, you can modify the DAX formula slightly to account for each record's position while keeping the logic for matching dates and visits intact.

Here is the DAX formula for the Calculated Column in Table 2:

CalculatedColumn =
VAR CurrentName = Table2[Name]
VAR CurrentEventDate = Table2[Event]
VAR CurrentPosition = Table2[RecordPosition]
RETURN
MAXX(
FILTER(
Table1,
Table1[Name] = CurrentName &&
Table1[Date] < CurrentEventDate
),
Table1[Visit]
)

 

Please mark this post as solution if it helps you. Appreciate Kudos.

Thank you, Farhan.
the provided DAX gives the out put 'visit' corresponding to min date by 'Name'. 
I will explain again. 
for example, Table 2 date 30-Jan-25 for A, all prior dates in Table 1 are (1-jan-25, 10-Jan-25 and 17-Jan-15). The first earlier date is  17-jan-25. The output in calculated column should be 'W3'.

The above provied DAX shows correspondong to lowest date 1-Jan-25, W1.

Eswar
Regular Visitor

Hi all,

Would you please help me this case? 

for example, Table 2 date 30-Jan-25 (looked up date) for A, all prior dates in Table 1 for A are (1-jan-25, 10-Jan-25 and 17-Jan-15). The first earlier date to looked up date is  17-jan-25. The output in calculated column expected is 'W3'.

The above provied DAX shows correspondong to lowest date 1-Jan-25, W1.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.