Forum Discussion

newtonian1991's avatar
1 year ago
Solved

Custom Measure and filter context help - Going crazy

Hello all, 

 

I have a powerbi report that need to find all employees  who had an active position/role on a particular date and look at the most recent payslip from that date and calculare their base salary. 

Im having issues wiht my custom measure that calculates the total base salary. The custom measure is meant to do the following. if permanenet staff find the latest payslip based on the data selected or if its a casual staff member find teh last 2 payslips and show the average of those two slips. 

Now on my table of all staff active during X date i have several staff members who's base salary is showing up as blank (majority are fine). But if i was to filter the table by an individual showing up blank then the base salary shows up.

Below is a list of jsut acouple of versions (so far im upto 11) of the custom measure i created with the support of AI. unfortunately neither of them work. I've also uploaded a photo. 

Unfortunately i cant share the PBIX as it contains sensitive infromation. 

Cheers Greg

Base Salary = 
VAR SelectedDate = MIN(DateTable[Date])

VAR Perm =
   ( IF(
        SelectedDate <= TODAY(),
        CALCULATE(
            LASTNONBLANK(
                MicroPay_ipvRBEmpTransTotalsALL[Taxable Income],
                NOT ISBLANK(MicroPay_ipvRBEmpTransTotalsALL[Taxable Income])
            ),
            FILTER(
                MicroPay_ipvRBEmpTransTotalsALL,
                MicroPay_ipvRBEmpTransTotalsALL[Period End Date] <= SelectedDate &&
                MicroPay_ipvRBEmpTransTotalsALL[Period End Date] > SelectedDate - 14
            )
        ),
        BLANK()
    ))*26

VAR CAS =
    (IF(
        SelectedDate <= TODAY(),
        CALCULATE(
            AVERAGE(MicroPay_ipvRBEmpTransTotalsALL[Taxable Income]),
            FILTER(
                MicroPay_ipvRBEmpTransTotalsALL,
                MicroPay_ipvRBEmpTransTotalsALL[Period End Date] <= SelectedDate &&
                MicroPay_ipvRBEmpTransTotalsALL[Period End Date] > SelectedDate - 30
            )
        ),
        BLANK()
    ))*26

RETURN
    IF(
        SELECTEDVALUE(q2employee_pay_details[WGEA Employment Type]) = "Casual",
        CAS,
        Perm
    )


 

Base Salary3 = 
VAR SelectedDate = MIN(DateTable[Date])
VAR IsValidDate = SelectedDate <= TODAY()

VAR PermWindow =
    FILTER(
        MicroPay_ipvRBEmpTransTotalsALL,
        MicroPay_ipvRBEmpTransTotalsALL[Period End Date] <= SelectedDate &&
        MicroPay_ipvRBEmpTransTotalsALL[Period End Date] > SelectedDate - 14
    )

VAR CASWindow =
    FILTER(
        MicroPay_ipvRBEmpTransTotalsALL,
        MicroPay_ipvRBEmpTransTotalsALL[Period End Date] <= SelectedDate &&
        MicroPay_ipvRBEmpTransTotalsALL[Period End Date] > SelectedDate - 30
    )

VAR Perm =
    CALCULATE(
        LASTNONBLANK(
            MicroPay_ipvRBEmpTransTotalsALL[Taxable Income],
            NOT ISBLANK(MicroPay_ipvRBEmpTransTotalsALL[Taxable Income])
        ),
        PermWindow
    ) * 26

VAR CAS =
    CALCULATE(
        AVERAGE(MicroPay_ipvRBEmpTransTotalsALL[Taxable Income]),
        CASWindow
    ) * 26

VAR EmpType = MAXX(VALUES(q2employee_pay_details[WGEA Employment Type]), q2employee_pay_details[WGEA Employment Type])

RETURN
    IF(
        IsValidDate,
        SWITCH(
            EmpType,
            "Casual", CAS,
            Perm
        ),
        BLANK()
    )

 

Base Salary7 = 
VAR SelectedDate = MIN(DateTable[Date])
VAR IsValidDate = SelectedDate <= TODAY()

VAR EmpID = SELECTEDVALUE(q2employee_pay_details[emp_code])
VAR EmpType = SELECTEDVALUE(q2employee_pay_details[WGEA Employment Type])

VAR PermWindow =
    FILTER(
        MicroPay_ipvRBEmpTransTotalsALL,
        MicroPay_ipvRBEmpTransTotalsALL[Employee Code] = EmpID &&
        MicroPay_ipvRBEmpTransTotalsALL[Period End Date] <= SelectedDate &&
        MicroPay_ipvRBEmpTransTotalsALL[Period End Date] > SelectedDate - 14
    )

VAR CASWindow =
    FILTER(
        MicroPay_ipvRBEmpTransTotalsALL,
        MicroPay_ipvRBEmpTransTotalsALL[Employee Code] = EmpID &&
        MicroPay_ipvRBEmpTransTotalsALL[Period End Date] <= SelectedDate &&
        MicroPay_ipvRBEmpTransTotalsALL[Period End Date] > SelectedDate - 30
    )

VAR PermSalary =
    CALCULATE(
        LASTNONBLANK(
            MicroPay_ipvRBEmpTransTotalsALL[Taxable Income],
            NOT ISBLANK(MicroPay_ipvRBEmpTransTotalsALL[Taxable Income])
        ),
        PermWindow
    ) * 26

VAR CASSalary =
    CALCULATE(
        AVERAGE(MicroPay_ipvRBEmpTransTotalsALL[Taxable Income]),
        CASWindow
    ) * 26

RETURN
    IF(
        IsValidDate,
        SWITCH(
            TRUE(),
            EmpType = "Casual", CASSalary,
            NOT ISBLANK(EmpType), PermSalary,
            BLANK()
        ),
        BLANK()
    )



Base Salary 10 = 
VAR V_SelectedDate =
    MIN ( DateTable[Date] )

VAR V_IsValidDate =
    V_SelectedDate <= TODAY()

RETURN
IF (
    V_IsValidDate,
    SUMX (
        VALUES ( q2employee_pay_details[emp_code] ), 
        VAR V_EmpCode = q2employee_pay_details[emp_code]

        -- Determine Employment Type for current employee
        VAR V_EmpType =
            CALCULATE (
                MAX ( q2employee_pay_details[WGEA Employment Type] ),
                ALL ( q2employee_pay_details ),
                q2employee_pay_details[emp_code] = V_EmpCode
            )

        -- Define filter windows
        VAR V_PermWindow =
            FILTER (
                ALL ( MicroPay_ipvRBEmpTransTotalsALL ),
                MicroPay_ipvRBEmpTransTotalsALL[Employee Code] = V_EmpCode &&
                MicroPay_ipvRBEmpTransTotalsALL[Period End Date] <= V_SelectedDate &&
                MicroPay_ipvRBEmpTransTotalsALL[Period End Date] > V_SelectedDate - 14
            )

        VAR V_CASWindow =
            FILTER (
                ALL ( MicroPay_ipvRBEmpTransTotalsALL ),
                MicroPay_ipvRBEmpTransTotalsALL[Employee Code] = V_EmpCode &&
                MicroPay_ipvRBEmpTransTotalsALL[Period End Date] <= V_SelectedDate &&
                MicroPay_ipvRBEmpTransTotalsALL[Period End Date] > V_SelectedDate - 30
            )

        -- Perform salary calculations
        VAR V_PermSalary =
            CALCULATE (
                LASTNONBLANK (
                    MicroPay_ipvRBEmpTransTotalsALL[Taxable Income],
                    NOT ISBLANK ( MicroPay_ipvRBEmpTransTotalsALL[Taxable Income] )
                ),
                V_PermWindow
            ) * 26

        VAR V_CASSalary =
            CALCULATE (
                AVERAGE ( MicroPay_ipvRBEmpTransTotalsALL[Taxable Income] ),
                V_CASWindow
            ) * 26

        -- Final result based on employment type
        VAR _Result =
            SWITCH (
                TRUE(),
                V_EmpType = "Casual", V_CASSalary,
                NOT ISBLANK ( V_EmpType ), V_PermSalary,
                BLANK()
            )

        RETURN _Result
    )
)


 

  • Please see my final measure. 

    Annual FTE Active Taxable1 = 
    VAR SelectedDate = MIN(DateTable[Date])
    VAR EmploymentType = SELECTEDVALUE(q2employee_pay_details[WGEA Employment Type], "Permanent") -- fallback to avoid blank
    VAR HireDate = SELECTEDVALUE(q2employee_pay_details[date_hired])
    VAR HourlyRate = SELECTEDVALUE(MicroPay_eivEmpDetails[Normal Hourly Rate])
    VAR PTHours = SELECTEDVALUE(MicroPay_ipvRBEmpTransTotalsALL[Contract Hours])
    VAR DaysBack = IF(EmploymentType = "Casual", 365, 14)
    VAR Category =SELECTEDVALUE(MicroPay_eivEmpDetails[Employment Type])
    VAR employmentstatus = SELECTEDVALUE(q2employee_pay_details[WGEA Employment Status])
    
    VAR FilteredTable =
        FILTER(
            MicroPay_ipvRBEmpTransTotalsALL,
            MicroPay_ipvRBEmpTransTotalsALL[Period End Date] <= SelectedDate &&
            MicroPay_ipvRBEmpTransTotalsALL[Period End Date] > SelectedDate - DaysBack
        )
    
    VAR TotalIncome =
        SUMX(FilteredTable, MicroPay_ipvRBEmpTransTotalsALL[Taxable Income])
    
    VAR PayslipCount =
        COUNTROWS(
            SUMMARIZE(
                FilteredTable,
                MicroPay_ipvRBEmpTransTotalsALL[Period End Date]
            )
        )
    
    VAR AverageIncome =
        IF(
            EmploymentType = "Casual",
            HourlyRate*7.6*10,
            IF(Employmentstatus = "PT",(DIVIDE(TotalIncome, PayslipCount)/(PTHours*2))*76,DIVIDE(TotalIncome, PayslipCount)
        ))
    
    
    RETURN
        AverageIncome * 26  -- Annualized

7 Replies

  • Solved with the following Custome measure!

    Average Active Taxable Income = 
    VAR SelectedDate = MIN(DateTable[Date])
    VAR FilteredTable =
        FILTER(
            MicroPay_ipvRBEmpTransTotalsALL,
            MicroPay_ipvRBEmpTransTotalsALL[Period End Date] <= SelectedDate &&
            MicroPay_ipvRBEmpTransTotalsALL[Period End Date] > 
                SelectedDate - 
                    IF(
                        SELECTEDVALUE(q2employee_pay_details[WGEA Employment Type]) = "Casual",
                        30,
                        14
                    )
        )
    RETURN
        (AVERAGEX(
            FilteredTable,
            MicroPay_ipvRBEmpTransTotalsALL[Taxable Income]
        ))*26
  • Hello newtonian1991 

     

    Try this measure

    Average Active Taxable Income =
    VAR SelectedDate = MIN(DateTable[Date])
    VAR FilteredTable =
    FILTER(
    MicroPay_ipvRBEmpTransTotalsALL,
    MicroPay_ipvRBEmpTransTotalsALL[Period End Date] <= SelectedDate &&
    MicroPay_ipvRBEmpTransTotalsALL[Period End Date] >
    SelectedDate -
    IF(
    SELECTEDVALUE(q2employee_pay_details[WGEA Employment Type]) = "Casual",
    30,
    14
    )
    )
    RETURN
    AVERAGEX(
    FilteredTable,
    MicroPay_ipvRBEmpTransTotalsALL[Taxable Income]
    ) * 26

     

     

    Thanks,
     Pankaj Namekar | LinkedIn

    If this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.

    • newtonian1991's avatar
      newtonian1991
      Helper I

      Thanks, 

      but after doing this ive realised that there is an issue with my logic. 

      some casuals who worked 0 hours in a fortnight have no entry rather than an entry of 0. There for rather than calculating (0+X dollars)/2 it only sees one entry thus is effectively saying X dollars/1. 

      hope that makes sense.  

      • v-hashadapu's avatar
        v-hashadapu
        Community Support

        Hi newtonian1991 , From what i understand you have discovered the issue in you logic. So does this mean you have been able to solve your issue? If so, kindly share the details and mark it or any other helpful replies "Accept as Solution", this will help others with similar queries find the answer easily. If no, please share the details.
        Thank you.

  • v-hashadapu's avatar
    v-hashadapu
    Community Support

    Hi newtonian1991 , hope you are doing well, Just wanted to confirm, if your issue is solved as you said you realized the issue with your logic. If so, kindly share the details and mark it or any other helpful replies "Accept as Solution", this will help others with similar queries find the answer easily. If no, please share the details.
    Thank you.

  • v-hashadapu's avatar
    v-hashadapu
    Community Support

    Hi newtonian1991 , I hope you're doing well. I wanted to check if you had a chance to review the issue and verify if it has been resolved. If you have any information that addressed your needs, please share it and mark it as "Accept as Solution" to assist others in the community. Let me know if you have any further questions.

  • Please see my final measure. 

    Annual FTE Active Taxable1 = 
    VAR SelectedDate = MIN(DateTable[Date])
    VAR EmploymentType = SELECTEDVALUE(q2employee_pay_details[WGEA Employment Type], "Permanent") -- fallback to avoid blank
    VAR HireDate = SELECTEDVALUE(q2employee_pay_details[date_hired])
    VAR HourlyRate = SELECTEDVALUE(MicroPay_eivEmpDetails[Normal Hourly Rate])
    VAR PTHours = SELECTEDVALUE(MicroPay_ipvRBEmpTransTotalsALL[Contract Hours])
    VAR DaysBack = IF(EmploymentType = "Casual", 365, 14)
    VAR Category =SELECTEDVALUE(MicroPay_eivEmpDetails[Employment Type])
    VAR employmentstatus = SELECTEDVALUE(q2employee_pay_details[WGEA Employment Status])
    
    VAR FilteredTable =
        FILTER(
            MicroPay_ipvRBEmpTransTotalsALL,
            MicroPay_ipvRBEmpTransTotalsALL[Period End Date] <= SelectedDate &&
            MicroPay_ipvRBEmpTransTotalsALL[Period End Date] > SelectedDate - DaysBack
        )
    
    VAR TotalIncome =
        SUMX(FilteredTable, MicroPay_ipvRBEmpTransTotalsALL[Taxable Income])
    
    VAR PayslipCount =
        COUNTROWS(
            SUMMARIZE(
                FilteredTable,
                MicroPay_ipvRBEmpTransTotalsALL[Period End Date]
            )
        )
    
    VAR AverageIncome =
        IF(
            EmploymentType = "Casual",
            HourlyRate*7.6*10,
            IF(Employmentstatus = "PT",(DIVIDE(TotalIncome, PayslipCount)/(PTHours*2))*76,DIVIDE(TotalIncome, PayslipCount)
        ))
    
    
    RETURN
        AverageIncome * 26  -- Annualized