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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
rsbin
Super User
Super User

Help with Calculated Column

Hello,

Could use some guidance on accomplishing the following scenario.  Is using Earlier function the way to go? 

I have a "Payroll" table containing hours worked for each day for each employee.

I need to create a Summary Table such as the following:

Employee_Name PayWeekNum_2022 Facility PayWeekStart Monday Tuesday Wednesday Thursday Friday Saturday Sunday Sunday Prior
John Doe 2 ABC 01/10/2022     11.0 13.0 14.0 15.0 13.0  

Need help in creating a Calculated Column for the hours for the Sunday Prior.  (An unusual scenario, but trying to capture payroll errors).  Pay Week starts on Mondays.  So in the following example, I need the hours for John Doe, for Sunday of the previous Pay Week ( i.e. Sunday Jan 9, PayWeekStart of Jan 3, 2022, Day 7).

Appreciate any help and guidance appreciated.

Thanks and Best Regards,

1 ACCEPTED SOLUTION
speedramps
Super User
Super User

Hi rsbin

 

No need to use EARLIER, this is easier ....

 

Sunday prior =

-- get this weekdate

VAR myweekdate = SELECTEDVALUE(payroll [weekdate])  

--  gets the previous week

VAR prevweekdate = DATEADD(myweekdate ,-7,day)  

RETURN
-- gets prior sunday by removing the week filter and then getting the previous week


CALCULATE(payroll(Sunday),   
ALL(payroll, payroll[weekdate]),
payroll[weekdate] = prevweekdate)

 

I am a Power BI volunteer. Please click the thumbs up for me going to the effort of trying to helping you. Then click solved if I fix your problem. One problem per ticket please. If you need to expand or change your problem then please raise a new ticket and click solved on this one so we get kudos. Many thanks. 

View solution in original post

3 REPLIES 3
speedramps
Super User
Super User

Hi rsbin

 

No need to use EARLIER, this is easier ....

 

Sunday prior =

-- get this weekdate

VAR myweekdate = SELECTEDVALUE(payroll [weekdate])  

--  gets the previous week

VAR prevweekdate = DATEADD(myweekdate ,-7,day)  

RETURN
-- gets prior sunday by removing the week filter and then getting the previous week


CALCULATE(payroll(Sunday),   
ALL(payroll, payroll[weekdate]),
payroll[weekdate] = prevweekdate)

 

I am a Power BI volunteer. Please click the thumbs up for me going to the effort of trying to helping you. Then click solved if I fix your problem. One problem per ticket please. If you need to expand or change your problem then please raise a new ticket and click solved on this one so we get kudos. Many thanks. 

@speedramps ,

Thanks for the response and for the suggestion to use Variables.

Will give this solution a try and will let you know how I make out.

Thanks again and Best Regards,

I am a Power BI volunteer. Please click the thumbs up now for me going to the effort of trying to helping you. Then click solved soon if I fix your problem so we get kudos. Many thanks. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.