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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
aar0n
Advocate II
Advocate II

Merging Two tables, one that has a continuous date column, and one that has a discrete date column

Hey guys,

 

I need to merge two tables in dax.. my "Online Date Table" Looks something like below..
Online Date:

NameOnline DateLocation
aaa1/1/2010x
aaa5/1/2012y
bbb4/1/2015x
ccc1/1/2011x
ccc3/1/2011 
ccc6/1/2011y

 

My Production Table looks like something below

 

Production Table:

NameValueDate
aaa101/1/2010
aaa22/1/2010
aaa43/1/2010
ccc51/1/2011
ccc22/1/2011
ccc33/1/2011
ccc74/1/2011
ccc55/1/2011
ccc46/1/2011
ccc27/1/2011

 

 

What i need to do is to merge both, so that i can see the "Online Date" and "Location" inside of my Production Table. i need to have that value show up for every "Name" and "Date" up until a new "Online Date" exceeds the True "Date" column.

for example, 

 

 

Example of Merged Table:

NameValueDateOnline DateLocation
aaa101/1/20101/1/2010x
aaa22/1/20101/1/2010x
aaa43/1/20101/1/2010x
ccc51/1/20111/1/2011x
ccc22/1/20111/1/2011x
ccc33/1/20113/1/2011 
ccc74/1/20113/1/2011 
ccc55/1/20113/1/2011 
ccc46/1/20116/1/2011y
ccc27/1/20116/1/2011y
1 ACCEPTED SOLUTION
v-yuezhe-msft
Employee
Employee

@aar0n,

Create new table using DAX  below.

Merge = 
GENERATEALL (
    Production,
    VAR Tdate =Production[Date]
    RETURN
        SELECTCOLUMNS (
            CALCULATETABLE ( 'Online Date', 'Online Date'[online date] = Tdate ),
            "online date",'Online Date'[online date],
            "Location", 'Online Date'[location]
            
        )
)


Create the following columns in the new table below.

New onlinedate = 
IF (
    Merge[online date]= BLANK (),
    CALCULATE (
        LASTNONBLANK ( Merge[online date], Merge[online date] ),
        FILTER ( ALLEXCEPT ( Merge, Merge[Name] ), Merge[Date] <= EARLIER ( Merge[Date]) )
    ),
    Merge[online date]
)
New Location = 
IF (
    Merge[Location] = BLANK (),
    CALCULATE (
        LASTNONBLANK ( Merge[Location], Merge[Location] ),
        FILTER ( ALLEXCEPT ( Merge, Merge[Name] ), Merge[Date] <= EARLIER ( Merge[Date])&&Merge[New onlinedate]=EARLIER(Merge[New onlinedate]) )
    ),
    Merge[Location]
)



Regards,
Lydia

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

View solution in original post

2 REPLIES 2
v-yuezhe-msft
Employee
Employee

@aar0n,

Create new table using DAX  below.

Merge = 
GENERATEALL (
    Production,
    VAR Tdate =Production[Date]
    RETURN
        SELECTCOLUMNS (
            CALCULATETABLE ( 'Online Date', 'Online Date'[online date] = Tdate ),
            "online date",'Online Date'[online date],
            "Location", 'Online Date'[location]
            
        )
)


Create the following columns in the new table below.

New onlinedate = 
IF (
    Merge[online date]= BLANK (),
    CALCULATE (
        LASTNONBLANK ( Merge[online date], Merge[online date] ),
        FILTER ( ALLEXCEPT ( Merge, Merge[Name] ), Merge[Date] <= EARLIER ( Merge[Date]) )
    ),
    Merge[online date]
)
New Location = 
IF (
    Merge[Location] = BLANK (),
    CALCULATE (
        LASTNONBLANK ( Merge[Location], Merge[Location] ),
        FILTER ( ALLEXCEPT ( Merge, Merge[Name] ), Merge[Date] <= EARLIER ( Merge[Date])&&Merge[New onlinedate]=EARLIER(Merge[New onlinedate]) )
    ),
    Merge[Location]
)



Regards,
Lydia

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

sorry for the late reply, but thank you very much! this is exactly what i was trying to do!

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.