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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
REngels
Frequent Visitor

Hw do I add a column to a table where a date is between two dates in a second table?

I am trying to add a column to table (w). Each row of table (w) is an activity that occurred on a date.  The new value I want to add is the name of a date range stored in a different table (s). This SQL statment would get me what I want, but I'm struggling to write it in DAX. Suggestions?

 

Select s. sprintname, w.key, w.loggedtime, w.user

From sprints s, worklogs w

Where w.key = s.key

And wl.timeentrydate between s.sprintstartdate and s.sprintenddate;

 

I don't necessarily need to add the value to (w). Any solution that will allow me to associate the date with the date range will be great.

 

Thanks.

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @REngels ,

 

I think you can try this code to create a caluclated column in table w.

sprintname =
CALCULATE (
    MAX ( S[sprintname] ),
    FILTER (
        S,
        S[Key] = EARLIER ( W[Key] )
            && S[sprintstartdate] <= EARLIER ( W[timeentrydate] )
            && S[sprintenddate] >= EARLIER ( W[timeentrydate] )
    )
)

My Sample:

S

RicoZhou_0-1661759107569.png

W

RicoZhou_1-1661759118987.png

Result is as below

RicoZhou_2-1661759129247.png

 

Best Regards,
Rico Zhou

 

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

1 REPLY 1
v-rzhou-msft
Community Support
Community Support

Hi @REngels ,

 

I think you can try this code to create a caluclated column in table w.

sprintname =
CALCULATE (
    MAX ( S[sprintname] ),
    FILTER (
        S,
        S[Key] = EARLIER ( W[Key] )
            && S[sprintstartdate] <= EARLIER ( W[timeentrydate] )
            && S[sprintenddate] >= EARLIER ( W[timeentrydate] )
    )
)

My Sample:

S

RicoZhou_0-1661759107569.png

W

RicoZhou_1-1661759118987.png

Result is as below

RicoZhou_2-1661759129247.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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