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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Anonymous
Not applicable

How to merge 2 tables using interval of dates

Hello!

In my previous post I asked how to prepare dataset for resource load.

For example, for every row of db_task table

Nikolai_0-1642676193226.png

I need to recieve this in another table:

Nikolai_2-1642676373917.png

The solution was to add a table on DAX:

 

clx_ResourcePlans = 
    SUMMARIZE(
        filter(
            CROSSJOIN(db_assignment, Local_DateTime),
					Local_DateTime[Date]>=db_assignment[planned_start]
					&& Local_DateTime[Date]<=db_assignment[planned_finish]
					&& NOT(Local_DateTime[IsHolidayInRussia])
        ),
        db_assignment[task_id], db_assignment[user_id], Local_DateTime[Date], "_plan", round(sum(db_assignment[DailyHours]), 2), "_fact", 0
    )

 

Then, I made another table for facts:

 

clx_ResourceFacts = 
    SUMMARIZE(
        FILTER(
            CROSSJOIN(db_task, db_time_entry),
			db_task[id]==db_time_entry[task_id]
            && db_time_entry[is_billable]="t")
        ,
        db_time_entry[task_id], db_time_entry[user_id], db_time_entry[for_date], "_plan", 0, "_fact", round(sum(db_time_entry[hours]), 2)
    )

 

In order to compare plans an facts, I append two tables:

 

clx_ResourceLoad = UNION(clx_ResourcePlans, clx_ResourceFacts)

 

Now the problem is that UNION expects, that I need two tables with the same structure. The same structure means the same number of columns. The matching is based on the position of the column in the table.

As you can see, I even add "_plan" column to clx_ResourceFacts table and "_fact" - to clx_ResourcePlans table.

But it did not help. My tables have different sequence of columns. An I get something like this

Nikolai_3-1642677469415.png

How can I solve this? 

I read, that it is strongly recommended to have a look at Append and Merge transformations in Power Query instead of combining tables in DAX.

But I don't know how to merge tables in DAX using advanced condition, like

 

Local_DateTime[Date]>=db_assignment[planned_start]
&& Local_DateTime[Date]<=db_assignment[planned_finish]

 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@Anonymous If I am following this, use SELECTCOLUMNS to get your two tables to have the same order and names of columns prior to UNION.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

1 REPLY 1
Greg_Deckler
Community Champion
Community Champion

@Anonymous If I am following this, use SELECTCOLUMNS to get your two tables to have the same order and names of columns prior to UNION.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors
Top Kudoed Authors