Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Relationship is not working as expected.

I can't figure out how to get the table relationships to work.

I have a unique master of employees, stores and specialty.

 

employees

employee_cdemployee_name
100Jennifer
101Robert
102Olive

stores

store_cdstore_name
200StoreA
201StoreB
202StoreC
203StoreD

specialty

specialty_cdspecialty
10PC
20Phone
30Software

 

There is a list of employees and the stores they are responsible for.

repstore

store_cd(store_name)employee_cd(employee_name)
200StoreA100Jennifer
201StoreB100Jennifer
201StoreB102Olive
202StoreC100Jennifer
202StoreC102Olive
202StoreC101Robert
203StoreD101Robert

 

I also have employee’s specialty table 

employee_specialty

employee_cd(employee_name)specialty_cd(specialty)
100Jennifer10PC
100Jennifer20Phone
102Olive30Software
102Olive20Phone
101Robert30Software
101Robert10PC

 

This relation works.

but seems this is not working.

 

What I want to show is the name of the store, the names of the employees, and the specialties of them.

Can anyone tell me what I need to modify?

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Anonymous ,

    Why the visual can't display the data normally? It is due to there is no direct relationship between the table 'specialty' and the table 'employee'&'store'...

    You can create a measure as below to get the specialty, please find the details in the attachment.

    Specialty Name = 
    VAR _selempname =
        SELECTEDVALUE ( 'employees'[employee_name] )
    VAR _selstore =
        SELECTEDVALUE ( 'stores'[store_name] )
    VAR _storecd =
        CALCULATE (
            MAX ( 'stores'[store_cd] ),
            FILTER ( 'stores', 'stores'[store_name] = _selstore )
        )
    VAR _rpempcd =
        CALCULATE (
            MAX ( 'repstore'[employee_cd] ),
            FILTER ( 'repstore', 'repstore'[store_cd] = _storecd )
        )
    VAR _spcds =
        CALCULATETABLE (
            VALUES ( 'employee_specialty'[specialty_cd] ),
            FILTER ( 'employee_specialty', 'employee_specialty'[employee_cd] = _rpempcd )
        )
    VAR _specialty =
        CONCATENATEX (
            FILTER ( 'specialty', 'specialty'[specialty_cd] IN _spcds ),
            'specialty'[specialty],
            ", "
        )
    RETURN
        _specialty

    Best Regards

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

    Why the visual can't display the data normally? It is due to there is no direct relationship between the table 'specialty' and the table 'employee'&'store'...

    You can create a measure as below to get the specialty, please find the details in the attachment.

    Specialty Name = 
    VAR _selempname =
        SELECTEDVALUE ( 'employees'[employee_name] )
    VAR _selstore =
        SELECTEDVALUE ( 'stores'[store_name] )
    VAR _storecd =
        CALCULATE (
            MAX ( 'stores'[store_cd] ),
            FILTER ( 'stores', 'stores'[store_name] = _selstore )
        )
    VAR _rpempcd =
        CALCULATE (
            MAX ( 'repstore'[employee_cd] ),
            FILTER ( 'repstore', 'repstore'[store_cd] = _storecd )
        )
    VAR _spcds =
        CALCULATETABLE (
            VALUES ( 'employee_specialty'[specialty_cd] ),
            FILTER ( 'employee_specialty', 'employee_specialty'[employee_cd] = _rpempcd )
        )
    VAR _specialty =
        CONCATENATEX (
            FILTER ( 'specialty', 'specialty'[specialty_cd] IN _spcds ),
            'specialty'[specialty],
            ", "
        )
    RETURN
        _specialty

    Best Regards

    • Anonymous's avatar
      Anonymous
      Not applicable

      Anonymous 
      Thank you for your help.

      This is very helpful😊 I was able to achieve what I wanted to do.