Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
sidexcel
Helper I
Helper I

US Payroll per Period Comparision

Background:

We process payroll two times a month: on the 15th of the month and the last day of the month. You may ignore issues around weekend/holidays for this problem.

 

Problem:

I am trying to create a measure to calculate payroll in the last pay period. Eg. for the month of October 31, 2021 the previous pay period will be October 15, 2021. 

 

I have a Fact Table (PayRegister) and a CalendarTable

Payroll DateEMP IDSalary
1/15/20221001000
1/31/20221001000
2/15/20221001100
2/28/20221001100
3/15/20221001200

 

I have created the following measures:

 

 

PayDateCurrent = MAX(PayRegister[Payroll Date])   -- calculates current payroll date 
PayDatePrevious= 

IF (

DAY ( [PayDateCurrent] ) > 15,

EOMONTH ( [PayDateCurrent], -1 ) + 15,

EOMONTH ( [PayDateCurrent], -1 )  -- calculates previous payroll date

 

 

 

 

WageCurrentPeriod = SUM(PayRegister[Salary])
WagePreviousPeriod = CALCULATE( [WagesCurrentPeriod], [PayDatePrevious])

 

 


The problem I am facing is that WagePreviousPeriod is not showing a syntax error: Calculation error in measure 'PayRegister'[WagesPreviousPeriod]: A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expression. This is not allowed.

 

Does anyone have any recommendation on what edits I need to make? 

 

Here is a link to the file

 

 

1 ACCEPTED SOLUTION

Hi @sidexcel 

 

Try this measure:

WagePreviousPeriod = 
VAR _Lat_Period =
    CALCULATE (
        MAX ( PayRegister[Payroll Date] ),
        FILTER (
            ALL ( PayRegister ),
            PayRegister[Payroll Date] < MAX ( PayRegister[Payroll Date] )
        )
    )
RETURN
    CALCULATE (
        [WageCurrentPeriod],
        FILTER ( ALLEXCEPT(  PayRegister,PayRegister[EMP ID]), PayRegister[Payroll Date] = _Lat_Period )
    )

 

Output:

 

VahidDM_0-1648073288057.png

 

 

 

Download the attached file.

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

View solution in original post

5 REPLIES 5
VahidDM
Super User
Super User

Hi @sidexcel 

 

Try this measure to find last period Payroll:

WagePreviousPeriod = 
VAR _Lat_Period =
    CALCULATE (
        MAX ( PayRegister[Payroll Date] ),
        FILTER (
            ALL ( PayRegister ),
            PayRegister[Payroll Date] < MAX ( PayRegister[Payroll Date] )
        )
    )
RETURN
    CALCULATE (
        [WageCurrentPeriod],
        FILTER ( ALL ( PayRegister ), PayRegister[Payroll Date] <= _Lat_Period )
    )

 

Download the sample file that is attached.

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Hi @VahidDM - thanks for the quick reply!

 

Thanks, I think there are some unexpected results. It seems to be aggregating results and allowing evaluation at the date and the employee level.

 

sidexcel_0-1647956496003.png

 

In this screenshot, value for 2/15/2022 should be $6,000 and for 2/28/2022 should be $4,900.

sidexcel_1-1647956496004.png

 

In the above screenshot, the value for 2/15/2022 for employee 100 should be $1,000.

I modified the DAX code slightly to make the last piece of the code say equal to Last Period (as opposted to less than equal to Last Period). 

 FILTER ( ALL ( PayRegister ), PayRegister[Payroll Date] = _Lat_Period )

 

However, it still evaluates at the period level but not at the employee level (I think it has something to do with the ALL function being used, it ignores the context for employee level. 

 

sidexcel_0-1647962736175.png

 

Works okay.

 

sidexcel_1-1647962744742.png

 

Does not evaluate at the employee level. 

 

Hi @sidexcel 

 

Try this measure:

WagePreviousPeriod = 
VAR _Lat_Period =
    CALCULATE (
        MAX ( PayRegister[Payroll Date] ),
        FILTER (
            ALL ( PayRegister ),
            PayRegister[Payroll Date] < MAX ( PayRegister[Payroll Date] )
        )
    )
RETURN
    CALCULATE (
        [WageCurrentPeriod],
        FILTER ( ALLEXCEPT(  PayRegister,PayRegister[EMP ID]), PayRegister[Payroll Date] = _Lat_Period )
    )

 

Output:

 

VahidDM_0-1648073288057.png

 

 

 

Download the attached file.

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Thank you - worked great! 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.