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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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