Forum Discussion

Belle2015's avatar
Belle2015
Icon for Helper II rankHelper II
1 year ago
Solved

Lookup to another table?

Hi, I have two tables, Table 1 has the Employee ID and Table 2 has the employee ID, expense type, value and transaction date. Some employees in table 1 may not have had an expense and be listed on table 2 for certain months or not at all. 

What I am trying to do is a matrix chart that will show all the employees listed in table 1 and give the total value and count of expenses submitted for each month that are for expense type company car and if the employee hasnt had any that it shows a zero.

Thanks in advance

Expected Output only with all employees showing and displaying  a 0 for any employees who dont have a company car expense

 

Table 1

Employee IDFuel Type Company
123456PetrolComp1
123457Diesel Comp1
123458ElectricComp1
123459Diesel Comp1
123460Diesel Comp1
123461Diesel Comp2
123462Diesel Comp2
123463ElectricComp2
123464ElectricComp1
123465ElectricComp1
123466PetrolComp1
123467ElectricComp1
123468ElectricComp1
123469PetrolComp2
123470PetrolComp2
123471Diesel Comp2
123472Diesel Comp2
123473Diesel Comp2
123474Diesel Comp2

 

Table 2

Employee IDExpense TypeTransaction DateTransaction Amount
123456Company Car12/03/20253.36
123457Car rental02/04/20253.36
123458Car rental17/03/2025111.44
123459Company Car03/04/202594.72
123460Company Car12/03/202596.08
123461Company Car02/02/202590.72
123462Company Car16/03/202585.89
123466Company Car17/03/202591.28
123467Company Car18/03/202589.95
123468Hotel19/03/202588.9
123469Public Transport20/03/20253.92
123470Company Car21/03/20253.92
123472Public Transport16/03/20253.92
123473Public Transport23/03/2025

3.92



  • Like this?

     

     

    Filters should ideally come from the dimension table. Your filter (Expense type) comes from the fact table.

     

    No need for a lookup, let the data model do the work for you

     

    showing and displaying  a 0 for any employees who dont have a company car expense

    Try not to do that, instead leave the row blank.

     

     

6 Replies

  • Hi Belle2015 

     

    Try the following:

    With Company Car Expense = 
    -- This calculated column returns TRUE if the employee has a "Company Car" expense in Table2
    VAR CompanyCarEmployee =
        -- Create a table of unique Employee IDs from Table2 where Expense Type is "Company Car"
        SUMMARIZE (
            FILTER ( Table2, Table2[Expense Type] = "Company Car" ),
            Table2[Employee ID]
        )
    RETURN
        -- For each row in Table1, return TRUE if the Employee ID exists in the filtered list
       IF ( Table1[Employee ID] IN CompanyCarEmployee, 1, 0 )
    

     

    Filter your visual to return 1 for the above calculated column or incorporate the filter in your measure.

  • Like this?

     

     

    Filters should ideally come from the dimension table. Your filter (Expense type) comes from the fact table.

     

    No need for a lookup, let the data model do the work for you

     

    showing and displaying  a 0 for any employees who dont have a company car expense

    Try not to do that, instead leave the row blank.

     

     

    • Belle2015's avatar
      Belle2015
      Icon for Helper II rankHelper II

      thank you, I got it, it was the relationship type 🙂 I was just over thinking it when it wasnt working!

    • Belle2015's avatar
      Belle2015
      Icon for Helper II rankHelper II

      Hi, This is what I was trying to do at first and had it show as blank line for the employee's without expenses until I apply the filter for company car, once I apply the filter it does not show the employee ID's without a blank like

       

  • Irwan's avatar
    Irwan
    Icon for Super User rankSuper User

    hello Belle2015 

     

    i am not sure but is this what you are looking for?

    if yes, then you can add if statement in your expense and count measure to replace blank value into zero.

    something like below

    Count = 
    var _Count =
    CALCULATE(
        COUNT('Table 2'[Transaction Amount]),
        'Table 2'[Expense Type]="Company Car"
    )
    Return
    IF(
        _Count=BLANK(),
        0,
        _Count
    )
    Expense = 
    var _Expense =
    CALCULATE(
        SUM('Table 2'[Transaction Amount]),
        'Table 2'[Expense Type]="Company Car"
    )
    Return
    IF(
        _Expense=BLANK(),
        0,
        _Expense
    )
    Hope this will help.
    Thank you.
  • v-kpoloju-msft's avatar
    v-kpoloju-msft
    Icon for Community Support rankCommunity Support

    Hi Belle2015,

    May i know has your issue been resolved? If the response provided by the super users lbendlindanextianIrwan, addressed your query, could you please confirm? It helps us ensure that the solutions provided are effective and beneficial for everyone.

    If yes, kindly accept the useful reply as a solution and give us Kudos. It would be appreciated.

    Thank you for your understanding!