Forum Discussion

gcaserta's avatar
gcaserta
Regular Visitor
4 years ago
Solved

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           

 

 

 

 

 

 

 

 

    

 

  • 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:

    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] )
    )

    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.

     

5 Replies

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

  • gcaserta's avatar
    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

    [email protected]EAXXX
    [email protected]EAXXX
    [email protected]EBYYY
    [email protected]ECZZZ
    [email protected]ECZZZ

     

     

    Table 2

     

    Primary Office CodeSecondary Office Code
    EAXXXEAXX1
    EAXXXEAXX2
    EAXXXEAXX3
    ECZZZECZZ1
    ECZZZECZZ2

     

    The result:

     

    [email protected]EAXXXEAXX1EAXX2EAXX3
    [email protected]EAXXXEAXX1EAXX2EAXX3
    [email protected]EBYYY   
    [email protected]ECZZZECZZ1ECZZ2ECZZ3
    [email protected]ECZZZECZZ1ECZZ2ECZZ3
    • v-zhangti's avatar
      v-zhangti
      Icon for Community Support rankCommunity Support

      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:

      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] )
      )

      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.