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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Merge two dataset on key and date with missing common dates

Hello,

 

I have two dataset with a common key and dates,the second dataset has a cumulative value over the date for each key.

 

My first dataset is :

 

KeyDate
key101/01/2019
key103/01/2019
key109/01/2019
key203/01/2019
key205/01/2019
key306/01/2019

 

My second dataset :

 

KeyDateCumulative value
key101/01/20191
key106/01/20193
key201/01/201815
key208/01/201825
key305/01/201915

 

I want to add the Cumulative value of my second dataset in my first but: my second dataset don't have all dates listed in the first dataset.

If a date is missing in the first dataset the value should be the one we find at the earliest date for the same key in the second dataset.

 

The expected result for this should be :

KeyDateCumulative value
key101/01/20191
key103/01/20191
key109/01/20193
key203/01/201925
key205/01/201925
key306/01/201915

 

Any idea how to proceed ?

(to note: dates in first dataset will only be more recent than the second dataset, so we won't be looking for a value from a previous date in the second dataset)

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Here is a calculated column expression you can try on your first table to get your desired result.  It assumes there is no relationship between the two table

 

Cumul Value =
VAR vThisDate = T1[Date]
VAR vThisKey = T1[Key]
VAR vResult =
    CALCULATE (
        LASTNONBLANKVALUE (
            T2[Date],
            MAX ( T2[Cumulative Value] )
        ),
        T2[Key] = vThisKey,
        T2[Date] <= vThisDate
    )
RETURN
    vResult

 

Regards,

Pat





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

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
Microsoft Employee

Here is a calculated column expression you can try on your first table to get your desired result.  It assumes there is no relationship between the two table

 

Cumul Value =
VAR vThisDate = T1[Date]
VAR vThisKey = T1[Key]
VAR vResult =
    CALCULATE (
        LASTNONBLANKVALUE (
            T2[Date],
            MAX ( T2[Cumulative Value] )
        ),
        T2[Key] = vThisKey,
        T2[Date] <= vThisDate
    )
RETURN
    vResult

 

Regards,

Pat





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

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Hello @mahoneypat ,

Thank you for the calculated column expression, when I add it I have the following error message:

DAX comparison operations do not support comparing values of type Text with values of type Date. Consider using the VALUE or FORMAT function to convert one of the values.

 

I checked the date column of my two tables, the data type is date for both and I formated them in the same fashion ("03/14/2001 (mm/dd/yyyy)"), should I check something else ?

 

EDIT:

My bad, T2[Cumulative Value] was not defiend as Decimal type.

It is done now but the result is "1" for all the rows in the new column.

 

My key column (categorical values) is in text format, could it be the reason ?

EDIT2:
I was missing a bracket, working perfectly! Thank you @mahoneypat 

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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