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
Malsk1_1
Helper II
Helper II

Lookup shift date in a payroll period date range

Hi All,

 

I have 2 tables:

 

Payroll Shifts & Payroll Schedule.

 

Payroll Schedule has the following data points:

 

Payroll PeriodPayroll Period NameStart DateEnd Date
31/01/2023Jan 202327/12/202223/01/2023
28/02/2023Feb 202324/01/202320/02/2023
30/03/2023Mar 202321/02/202327/03/2023

The start and end date represent the shift dates within the payroll period.

 

Payroll Shifts has the following data attributes:

 

Employee NameEmployee IDShift Date
John12328/12/2022
Jane43224/01/2023
Fred98729/12/2022

 

The outcome I want on the Payroll Shift table is as follows:

 

Employee NameEmployee IDShift DatePayroll Period NamePayroll Period
John12328/12/2022Jan 202331/01/2023
Jane43224/01/2023Feb 202328/03/2023
Fred98729/12/2022Jan 202331/01/2023

 

And so on - the above is just the core example - how can i do this without any natural join between the 2 tables?

I then need that Payroll period as a date slicer for the report.

 

I would prefer it in M if possible..

 

Thanks in advance.

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @Malsk1_1 

Here are the steps you can refer to :
(1)We can click "Custom Column" in Power Query Editor:

vyueyunzhmsft_0-1675821426948.png

(2)We put this two in two custom columns.

try Table.SelectRows(#"Payroll Schedule",(y)=> 
y[Start Date]<=[Shift Date] and y[End Date]>=[Shift Date])[Payroll Period Name]{0} otherwise null
try Table.SelectRows(#"Payroll Schedule",(y)=> 
y[Start Date]<=[Shift Date] and y[End Date]>=[Shift Date])[Payroll Period]{0} otherwise null

(3)Then we can meet your need:

vyueyunzhmsft_1-1675821468689.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

6 REPLIES 6
Malsk1_1
Helper II
Helper II

@Ashish_Mathur thank you for your input - on this occasion i went with the M-Query although it is slow performance.

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Malsk1_1
Helper II
Helper II

@v-yueyunzh-msft thank you for the M-Query - it has worked, but it is quite slow - when i refresh the data it goes row by row and can take up to 5 mins to refresh 180 rows - this data is only going to grow and may eventually become problematic - can this be tuned?  All data is in excels that are on Sharepoint Online

Hi, @Malsk1_1 

According to your description, this new column is very slow, but it is not complicated for this creation logic, that is, each row is searched row by row on Table 1, and the conditions are met and returned.And according to your needs, you need to iterate through all the rows in Table 1 to get the value.

You can try publishing PBIX to Service for refresh and see if it takes a long time.
If so, you may need to use measures to calculate these two columns.

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

Ashish_Mathur
Super User
Super User

Hi,

These calculated column formulas works

Column = CALCULATE(MAX('Payroll schedule'[Payroll Period Name]),FILTER('Payroll schedule','Payroll schedule'[Start Date]<=EARLIER('Payroll shift'[Shift Date])&&'Payroll schedule'[End Date]>=EARLIER('Payroll shift'[Shift Date])))
Column 2 = CALCULATE(MAX('Payroll schedule'[Payroll Period]),FILTER('Payroll schedule','Payroll schedule'[Start Date]<=EARLIER('Payroll shift'[Shift Date])&&'Payroll schedule'[End Date]>=EARLIER('Payroll shift'[Shift Date])))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yueyunzh-msft
Community Support
Community Support

Hi , @Malsk1_1 

Here are the steps you can refer to :
(1)We can click "Custom Column" in Power Query Editor:

vyueyunzhmsft_0-1675821426948.png

(2)We put this two in two custom columns.

try Table.SelectRows(#"Payroll Schedule",(y)=> 
y[Start Date]<=[Shift Date] and y[End Date]>=[Shift Date])[Payroll Period Name]{0} otherwise null
try Table.SelectRows(#"Payroll Schedule",(y)=> 
y[Start Date]<=[Shift Date] and y[End Date]>=[Shift Date])[Payroll Period]{0} otherwise null

(3)Then we can meet your need:

vyueyunzhmsft_1-1675821468689.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

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.