Forum Discussion

DiamonDave's avatar
DiamonDave
New Member
2 years ago
Solved

DAX Query two tables - Need help

Hi everyone,   I have two queries on a legacy data set that I am scratching my head over.   Number 1: I have two tables that are related by the FULLNAME field.  When an employee leaves, a record...
  • Anonymous's avatar
    Anonymous
    2 years ago

    HI DiamonDave,

    #1, It seems like in Sale tabel the 'name' field seems named 'Salesperson', perhaps you can use this to replace the searched table fields.

     

    SalesContact =
    LOOKUPVALUE ( Employee[Contact], Employee[FullName], Sales[Salesperson], BLANK () )

     

    Comment:

    Employee table means the table that you stored the employee information with contact.  Sales Table is the table that you want to add the contact info that lookup from employee table.

    #2, OK, it seems like the target is a static value and sales table already include date values.

    You can take a look at the following measure formula: (I try to add a variable table to summary total field values based on current salesperson and date year, month group. Then get the average from variable table result and divide with target to get the percentage value)

     

    Employee AVG =
    VAR target = 15000
    VAR currEmployee =
        SELECTEDVALUE ( Sales[Salesperson] )
    VAR startDate =
        CALCULATE (
            MAX ( Employee[Date] ),
            FILTER ( ALLSELECTED ( Employee ), [FullName] = currEmployee )
        )
    VAR summary =
        SUMMARIZE (
            ADDCOLUMNS (
                FILTER (
                    ALLSELECTED ( Sales ),
                    [Salesperson] = currEmployee
                        && [Date] >= startDate
                ),
                "Year", YEAR ( Sales[Date] ),
                "Month", MONTH ( Sales[Date] )
            ),
            [Salesperson],
            [Year],
            [Month],
            "monthlyTotal", SUM ( Sales[Total] )
        )
    RETURN
        DIVIDE ( AVERAGEX ( summary, [monthlyTotal] ), target, BLANK () )

     

    Regards,

    Xiaoxin Sheng