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
Anonymous
Not applicable

Merging and Filtering related data with unique entries

I have 2 data tables with related data, and I'm having trouble relating the data between them.  I am trying to track the planning progress for an upcoming event.  The event scope is broken down on the worklist, which is broken down into jobcards, which are assigned to a primary contractor to plan (table 1).  The primary contractor breaks down a job card into packages, and then the packages are assigned to themselves as well as other contractors (sub contractors) (table2). 

Table 1:

WorklistJobcard...Primary Contractor
123ABC...A
456CDE...B
789FGH...C
101IJK...A
112LMN...C

Table 2:

WorklistJobcardPackage...Sub Contractor
123ABCABC.1...A
123ABCABC.2...B
456ABCABC.3...B
456CDECDE.1....B
101LMNLMN.1...C
112LMNLMN.2...C

 

These tables are used to track planning progress, so every line on each table is valuable information.    I want to relate the two tables by merging entries based on worklist# and job card number to identify progress in planning, but I also want to maintain the unique entries - which indicate a gap or lack of progress from the respective contractor.  I need to create visual tables that summarize data from both tables (see the visual table for dashboard)  

 

Visual table for dashboard:

ContractorJobcard Count by contractor
(Table 1)
Jobcard Count by Contractor
(table 2)
Package Count
(Table 2)
A211
B123
C212

 

I've tried establishing relationships (1:1, 1:*, *:*) between the two tables, but I lose the unique entries for one or both of the tables depending on how Power-BI cross filters.  I think I need to create a new calculated table, and establish 1:* relationships to each table.  I'm facing similar struggles when merging the fields into a calculated table (losing items that are unique to each table, and problems when "duplicate" items are in table 2.)  Ideally i'd like to see which scope items have been identified in table 1, but are missing from table 2 and vice versa.  I'm new to power bi so if anyone has another suggestion, let me know. 

 

Summary Table: 

WorklistJobcard
123ABC
456ABC
456CDE
101LMN
112LMN
789FGH
101IJK
1 ACCEPTED SOLUTION

@Anonymous,

 

This can be solved by creating a Contractor dimension table (star schema).

 

1. Create a table with a distinct list of all primary contractors and subcontractors. This can be done in Power Query or DAX. Here's the DAX calculated table:

 

Contractor = 
DISTINCT (
    UNION (
        DISTINCT ( Table1[Primary Contractor] ),
        DISTINCT ( Table2[Sub Contractor] )
    )
)

 

2. Create relationships:

 

DataInsights_0-1628637559208.png

 

3. Create measures:

 

Jobcard Count by Primary Contractor (Table 1) = 
VAR vCount =
    DISTINCTCOUNT ( Table1[Jobcard] )
VAR vResult =
    IF ( ISBLANK ( vCount ), 0, vCount )
RETURN
    vResult

Jobcard Count by Primary Contractor (Table 2) = 
VAR vCount =
    DISTINCTCOUNT ( Table2[Jobcard] )
VAR vResult =
    IF ( ISBLANK ( vCount ), 0, vCount )
RETURN
    vResult

Package Count = 
VAR vCount =
    COUNT ( Table2[Jobcard] )
VAR vResult =
    IF ( ISBLANK ( vCount ), 0, vCount )
RETURN
    vResult

 

4. Create matrix using Contractor[Contractor] as rows (this is the Contractor dimension table):

 

DataInsights_1-1628637894880.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
V-pazhen-msft
Community Support
Community Support

@Anonymous 

We usually create 1 to many relationship, and create measures for those fields that cannot provide expected output. Please provide a full short sample of the 2 tables and the exact expected output from that sample.

 

 

Paul Zheng _ Community Support Team

Anonymous
Not applicable

Samples of each table are below:

Table 1:

WorklistJobcard...Primary Contractor
123ABC...A
456CDE...B
789FGH...C
101IJK...A
112LMN...C
131OPQ...D

Table 2:

WorklistJobcardPackage...Sub Contractor
123ABCABC.1...A
123ABCABC.2...B
456ABCABC.3...B
456CDECDE.1....B
101LMNLMN.1 C
101LMNLMN.2...E
112LMNLMN.3...C

 

Desired Output table: 

ContractorJobcard Count by Primary Contractor
(Table 1)
Jobcard Count by Primary Contractor
(Counting from Table 2)
Package Count
(Table 2)
A211
B123
C212
D100
E011

 

The problem with the one to many relationship is that it will filter unique values from one or both of the sample tables: 

* Contractor D was assigned 1 jobcard in table 1, but has not created any packages in table 2. 

* Contractor E is not a primary contractor for any job card on table 1, but they are a subcontractor assigned Package LMN.2 for Jobcard 101-LMN (table 2). 

 

I am also having trouble counting packages by contractor using measured values - I can only count packages when a specific contractor is the primary contractor and the subcontractor.  

@Anonymous,

 

This can be solved by creating a Contractor dimension table (star schema).

 

1. Create a table with a distinct list of all primary contractors and subcontractors. This can be done in Power Query or DAX. Here's the DAX calculated table:

 

Contractor = 
DISTINCT (
    UNION (
        DISTINCT ( Table1[Primary Contractor] ),
        DISTINCT ( Table2[Sub Contractor] )
    )
)

 

2. Create relationships:

 

DataInsights_0-1628637559208.png

 

3. Create measures:

 

Jobcard Count by Primary Contractor (Table 1) = 
VAR vCount =
    DISTINCTCOUNT ( Table1[Jobcard] )
VAR vResult =
    IF ( ISBLANK ( vCount ), 0, vCount )
RETURN
    vResult

Jobcard Count by Primary Contractor (Table 2) = 
VAR vCount =
    DISTINCTCOUNT ( Table2[Jobcard] )
VAR vResult =
    IF ( ISBLANK ( vCount ), 0, vCount )
RETURN
    vResult

Package Count = 
VAR vCount =
    COUNT ( Table2[Jobcard] )
VAR vResult =
    IF ( ISBLANK ( vCount ), 0, vCount )
RETURN
    vResult

 

4. Create matrix using Contractor[Contractor] as rows (this is the Contractor dimension table):

 

DataInsights_1-1628637894880.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.