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
RafDelgado
Helper II
Helper II

Join or add column based on multiple date range and categories

 

Hey All, 

 

I'm working with two tables that contain 44k rows of data from Dataverse and an API web call. One table has the customer information and the type of service they had during a period. The second is a table which shows all the data time entries by everyone. 

 

CRM Data Verse

CustomerStartDateEndDateServiceTypeContractName
Customer A12/04/201812/04/2019Service Type 1Contract 1
Customer B12/07/201812/07/2019Service Type 1Contract 2
Customer A13/06/201813/06/2022Service Type 2Contract 3

 

API

AgentServiceTypeCustomerCreation DateTimeSpent
Agent AService Type 1Customer A22/04/2018150
Agent BService Type 2Customer A14/06/2020160
Agent AService Type 1 Customer B13/07/20195

 

I created a list first, which on query editor works as expected, but it's ridiculously slow to load on refresh as it's almost manually checking on each 44k row.

 

List.First(
Table.SelectRows(
Contract,
(r) =>
r[StartDate] < [CreatedDate]
and
r[EndDate] > [CreatedDate]
and
r[Customer] = [Customer]
and
r[ServiceType] = [ServiceType]
)[ContractName]
)

 

 

 

Is there a way to add a column to the second table on the data model based on multiple conditions between X date that matches multiple columns and returns a string value that's a quicker way to join? Like the below?

 

API

AgentServiceTypeCustomerCreation DateTimeSpentContractName
Agent AService Type 1Customer A22/04/2018150Contract 1
Agent BService Type 2Customer A14/06/2020160Contract 2
Agent AService Type 2Customer B13/07/20195Contract 3
Agent BService Type 1Customer A23/07/2018100Contract 1

 

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

Hi @RafDelgado ,

Please have a try.

Create a measure.

Measure =
CALCULATE (
    MAX ( TableA[ContractName] ),
    FILTER (
        ALL ( TableA ),
        TableA[ServiceType] = SELECTEDVALUE ( API[ServiceType] )
            && TableA[Customer] = SELECTEDVALUE ( API[Customer] )
    )
)

Or a column.

column =
CALCULATE (
    MAX ( TableA[ContractName] ),
    FILTER (
        ( TableA ),
        TableA[ServiceType] = EARLIER ( API[ServiceType] )
            && TableA[Customer] = EARLIER ( API[Customer] )
    )
)

vpollymsft_0-1655692593870.png

 

Best Regards

Community Support Team _ Polly

 

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-rongtiep-msft
Community Support
Community Support

Hi @RafDelgado ,

Please have a try.

Create a measure.

Measure =
CALCULATE (
    MAX ( TableA[ContractName] ),
    FILTER (
        ALL ( TableA ),
        TableA[ServiceType] = SELECTEDVALUE ( API[ServiceType] )
            && TableA[Customer] = SELECTEDVALUE ( API[Customer] )
    )
)

Or a column.

column =
CALCULATE (
    MAX ( TableA[ContractName] ),
    FILTER (
        ( TableA ),
        TableA[ServiceType] = EARLIER ( API[ServiceType] )
            && TableA[Customer] = EARLIER ( API[Customer] )
    )
)

vpollymsft_0-1655692593870.png

 

Best Regards

Community Support Team _ Polly

 

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.