Forum Discussion

JustDavid's avatar
JustDavid
Icon for Helper V rankHelper V
1 month ago
Solved

Unable to create relationship

Hello PowerBI and DAX gurus, My end goal is to create a measure where I want to get the SUM of ([Hourly Rate] x [Number of Hours]) of each employee who works in that LOB in a given month. However, ...
  • Praful_Potphode's avatar
    Praful_Potphode
    1 month ago

    Hi JustDavid​ 

    try attached pbix.

    Salary Paid by LOB =
    SUMX (
        VALUES ( dimLOB[LOB] ),
        VAR CurrentLOB = dimLOB[LOB]
        VAR EmployeesInLOB =
            CALCULATETABLE (
                VALUES ( dimEmployee[EmpName] ),
                LOB[LOB] = CurrentLOB
            )
        VAR LOBResult =
            SUMX (
                EmployeesInLOB,
                VAR CurrentEmp = dimEmployee[EmpName]
    
                -- Split hours: everything except O/T 1.5, and O/T 1.5 separately
                VAR RegularHours =
                    CALCULATE (
                        SUM ( Payroll[Hours] ),
                        Payroll[EmpName] = CurrentEmp,
                        Payroll[Hour Types] <> "O/T 1.5"
                    )
                VAR OT15Hours =
                    CALCULATE (
                        SUM ( Payroll[Hours] ),
                        Payroll[EmpName] = CurrentEmp,
                        Payroll[Hour Types] = "O/T 1.5"
                    )
                VAR EffectiveHours = RegularHours + ( OT15Hours * 1.5 )
    
                VAR RateThisMonth =
                    CALCULATE (
                        AVERAGE ( Timesheets[Hourly Rate] ),
                        Timesheets[EmpName] = CurrentEmp
                    )
    
                VAR PayBeforeAllocation = EffectiveHours * RateThisMonth
    
                VAR EmpAllocation =
                    CALCULATE (
                        SUM ( LOB[Allocation] ),
                        LOB[EmpName] = CurrentEmp,
                        LOB[LOB] = CurrentLOB
                    )
    
                RETURN
                    PayBeforeAllocation * EmpAllocation
            )
        RETURN
            LOBResult
    )

    please give kudos or mark it as solution once resolved.

    Regards,

    praful