Forum Discussion

idage's avatar
idage
Icon for Helper I rankHelper I
3 years ago
Solved

RELATIONS IN POWER BI

Dear All, i need your help to understand...

I have to tables (simple tables):

TAB A

 

NOMECITTA
CARLOTTAPISA
FEDERICAFIRENZE
MIMMONAPOLI
PIERONAPOLI
MARCOMILANO

 

TAB B

 

NOMESCUOLA
IDADINI
CARLOTTAFIBONACCI
SALVATOREFERMI
FEDERICAFERMI
MIMMODINI
GIOVANNIBUONARROTI

 

I would like to realize a table like this:

 

NOMECITTASCUOLA
CARLOTTAPISAFIBONACCI
FEDERICAFIRENZEFERMI
MIMMONAPOLIDINI
PIERONAPOLI 
MARCOMILANO 
IDA DINI
SALVATORE FERMI
GIOVANNI BUONARROTI

 

Is it possible? How?

 

Thank you very much for your help.

 

 

 

  • Hey, 
    If you have access to Power Query, you can use Merge Queries, and use Full Outer Type. 

    The result should be something like the above. To get the NOME column to look like your result, you can use a query like: Table.AddColumn(#"Expanded Tab B", "NOME (Keep)", each if [NOME] = null then [NOME.1] else [NOME]) in PowerQuery to a column without null in the NOME column.

     

    If you want to do so in DAX, try something like:

    MergedTable = ADDCOLUMNS(
        DISTINCT(
            UNION(SELECTCOLUMNS('Tab A', "NOME", 'Tab A'[NOME]), SELECTCOLUMNS('Tab B', "NOME",('Tab B'[NOME])))
        ),
        "Citta", CALCULATE(MAX('Tab A'[CITTA]), 'Tab A'[NOME] = EARLIER([NOME])), 
        "Scuola", CALCULATE(MAX('Tab B'[SCUOLA]), 'Tab B'[NOME] = EARLIER([NOME]))
    )

3 Replies

  • Hey, 
    If you have access to Power Query, you can use Merge Queries, and use Full Outer Type. 

    The result should be something like the above. To get the NOME column to look like your result, you can use a query like: Table.AddColumn(#"Expanded Tab B", "NOME (Keep)", each if [NOME] = null then [NOME.1] else [NOME]) in PowerQuery to a column without null in the NOME column.

     

    If you want to do so in DAX, try something like:

    MergedTable = ADDCOLUMNS(
        DISTINCT(
            UNION(SELECTCOLUMNS('Tab A', "NOME", 'Tab A'[NOME]), SELECTCOLUMNS('Tab B', "NOME",('Tab B'[NOME])))
        ),
        "Citta", CALCULATE(MAX('Tab A'[CITTA]), 'Tab A'[NOME] = EARLIER([NOME])), 
        "Scuola", CALCULATE(MAX('Tab B'[SCUOLA]), 'Tab B'[NOME] = EARLIER([NOME]))
    )
    • idage's avatar
      idage
      Icon for Helper I rankHelper I

      Thank you very much for your reply but i need to show all names in the first column.  That could be possible managing relationship in power bi?

    • idage's avatar
      idage
      Icon for Helper I rankHelper I

      Thank you very much for your wonderful help!