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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
gcaserta
Regular Visitor

Create a new table starting from existing data

Hi to all

I have 2 tables with this structures:

 

Table 1

Column A: Employee  emails 

Column B: Code of Primary Offices

 

For this table I can have for different emails the same Code of Primary Company

 

Example

Employee  email A        Code of Primary Offices A

Employee  email B        Code of Primary Offices A

Employee  email C        Code of Primary Offices B

Employee  email D        Code of Primary Offices B

 

Table 2

Column A: Code of Primary Office

Column B: Code of Secondary Office

 

For this table I can have for the same Code Of Primary Office different Code of Secondary Company

Example:

Code Of Primary Office A       Code Of Secondary Office B

Code Of Primary Office A       Code Of Secondary Office C

Code Of Primary Office A       Code Of Secondary Office D

 

What I need to have and I ask your help is a Table with this structure:

 

Table New

 

Employee  email A        Code Of Primary Office A       Code Of Secondary Office B      Code Of Secondary Office C ......

 

Many thanks for your support           

 

 

 

 

 

 

 

 

    

 

1 ACCEPTED SOLUTION

Hi, @gcaserta 

 

You can try the following methods.

Column:

Secondary Office Code 1 = 
CALCULATE (
    MIN ( 'Table 2'[Secondary Office Code] ),
    FILTER (
        'Table 2',
        [Primary Office Code] = EARLIER ( 'Table 1'[Primary Office Code] )
    )
)
Secondary Office Code 2 = 
CALCULATE (
    MIN ( 'Table 2'[Secondary Office Code] ),
    FILTER (
        'Table 2',
        [Primary Office Code] = EARLIER ( 'Table 1'[Primary Office Code] )
            && [Secondary Office Code] <> EARLIER ( 'Table 1'[Secondary Office Code 1] )
    )
)
Secondary Office Code 3 = 
CALCULATE (
    MIN ( 'Table 2'[Secondary Office Code] ),
    FILTER (
        'Table 2',
        [Primary Office Code] = EARLIER ( 'Table 1'[Primary Office Code] )
            && [Secondary Office Code] <> EARLIER ( 'Table 1'[Secondary Office Code 1] )
            && [Secondary Office Code] <> EARLIER ( 'Table 1'[Secondary Office Code 2] )
    )
)

Table Result 1:

vzhangti_0-1652949166425.png

New Table:

Table Result 2 = 
UNION (
    SUMMARIZE ( 'Table 1', [Email], 'Table 1'[Primary Office Code] ),
    SUMMARIZE ( 'Table 1', [Email], 'Table 1'[Secondary Office Code 1] ),
    SUMMARIZE ( 'Table 1', [Email], 'Table 1'[Secondary Office Code 2] ),
    SUMMARIZE ( 'Table 1', [Email], 'Table 1'[Secondary Office Code 3] )
)

vzhangti_1-1652949240422.png

vzhangti_2-1652949263120.pngvzhangti_3-1652949290510.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

5 REPLIES 5
gcaserta
Regular Visitor

tables.PNG

Hi, @gcaserta 

 

You can try the following methods.

Column:

Secondary Office Code 1 = 
CALCULATE (
    MIN ( 'Table 2'[Secondary Office Code] ),
    FILTER (
        'Table 2',
        [Primary Office Code] = EARLIER ( 'Table 1'[Primary Office Code] )
    )
)
Secondary Office Code 2 = 
CALCULATE (
    MIN ( 'Table 2'[Secondary Office Code] ),
    FILTER (
        'Table 2',
        [Primary Office Code] = EARLIER ( 'Table 1'[Primary Office Code] )
            && [Secondary Office Code] <> EARLIER ( 'Table 1'[Secondary Office Code 1] )
    )
)
Secondary Office Code 3 = 
CALCULATE (
    MIN ( 'Table 2'[Secondary Office Code] ),
    FILTER (
        'Table 2',
        [Primary Office Code] = EARLIER ( 'Table 1'[Primary Office Code] )
            && [Secondary Office Code] <> EARLIER ( 'Table 1'[Secondary Office Code 1] )
            && [Secondary Office Code] <> EARLIER ( 'Table 1'[Secondary Office Code 2] )
    )
)

Table Result 1:

vzhangti_0-1652949166425.png

New Table:

Table Result 2 = 
UNION (
    SUMMARIZE ( 'Table 1', [Email], 'Table 1'[Primary Office Code] ),
    SUMMARIZE ( 'Table 1', [Email], 'Table 1'[Secondary Office Code 1] ),
    SUMMARIZE ( 'Table 1', [Email], 'Table 1'[Secondary Office Code 2] ),
    SUMMARIZE ( 'Table 1', [Email], 'Table 1'[Secondary Office Code 3] )
)

vzhangti_1-1652949240422.png

vzhangti_2-1652949263120.pngvzhangti_3-1652949290510.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

 

gcaserta
Regular Visitor

@amitchandak Hi replied with tables but i'm not sure if you can see them.

gcaserta
Regular Visitor

Hi Amitchandak

Below the sample. Honestly I didn't find how to send as attachment the files

Thanks 

 

Table 1

Email

Primary Office Code

john@test1.comEAXXX
smith@test2.comEAXXX
frank@test3.comEBYYY
michael@test4.comECZZZ
boris@test5.comECZZZ

 

 

Table 2

 

Primary Office CodeSecondary Office Code
EAXXXEAXX1
EAXXXEAXX2
EAXXXEAXX3
ECZZZECZZ1
ECZZZECZZ2

 

The result:

 

john@test1.comEAXXXEAXX1EAXX2EAXX3
smith@test2.comEAXXXEAXX1EAXX2EAXX3
frank@test3.comEBYYY   
michael@test4.comECZZZECZZ1ECZZ2ECZZ3
boris@test5.comECZZZECZZ1ECZZ2ECZZ3
amitchandak
Super User
Super User

@gcaserta ,
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.