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
Syndicate_Admin
Administrator
Administrator

Create a calculated column by comparing two dates from different tables in DirectQuery

Hello

I would like to create a calculated column in DirectQuery that sees if a particular record in table1 has the [date1] field not null. If it is non-null, take [date1] and if it is null, take [date2] from table2. Here is an example:

Table 1

IDFECHA1CODEDAX COLUMN
104/01/2020OF04/01/2020
201/05/2021FRI01/05/2021
3 IT04/01/2020
4 IT01/06/2022
501/04/2020FRI01/04/2020

tabla2

IDFECHA2CODE
104/01/2020OF
201/05/2021FRI
304/01/2020IT
4 01/06/2022IT
501/04/2020FRI

Is there a way to do this in DAX?

Greetings

1 REPLY 1
v-jingzhang
Community Support
Community Support

Hi @data_operador1 

 

Are both tables in DirectQuery mode? I'm afraid it's not possible to add this calculated column to a DirectQuery table as it will hit the following model limitation of DirectQuery. 

 

Limitations in calculated columns: Calculated columns are limited to being intra-row, as in, they can only refer to values of other columns of the same table, without the use of any aggregate functions. See About using DirectQuery in Power BI

 

Instead, you can try using a measure to get the expected date result. Remember to add 'Table 1'[ID] and 'Table 1'[CODE] to the same visual as well as the measure. 

Date =
IF (
    ISBLANK ( SELECTEDVALUE ( 'Table 1'[FECHA1] ) ),
    CALCULATE (
        SELECTEDVALUE ( 'Table 1'[FECHA1] ),
        FILTER (
            ALL ( 'Table 2' ),
            'Table 2'[ID] = MAX ( 'Table 1'[ID] )
                && 'Table 2'[CODE] = MAX ( 'Table 1'[CODE] )
        )
    ),
    SELECTEDVALUE ( 'Table 1'[FECHA1] )
)

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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