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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Count number of weeks from daily data

I have what is probably a very simple problem that I have been looking at too long and hope one of you can help me solve.
 
I have a payroll table with hours by employee by day. I am simply trying to write a measure that shows how many weeks they have worked.
 
4 tables (calendar, employee, location, and payroll) 
jroger911_0-1649955361383.jpeg

 

payroll table structure

jroger911_1-1649955375112.jpeg

 

I have been able to build many calaculations from these, but this one is the simplest thing I cannot get to work and have tried multiple methods.

jroger911_2-1649955434906.jpeg

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Sorry for the blurry images
I got the problem solved by changing the relationship between calendar and payroll to bi-directional

 

Now just trying to figure out how to speed up the DAX query becuase its slow when evaluating all employees (over 10K)

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Sorry for the blurry images
I got the problem solved by changing the relationship between calendar and payroll to bi-directional

 

Now just trying to figure out how to speed up the DAX query becuase its slow when evaluating all employees (over 10K)

Anonymous
Not applicable

Hi @Anonymous ,

 

You could get the start date and end date by using min() and max() function for each user.

start_ = calculate(MIN('payroll'[date]),ALLEXCEPT('payroll','payroll'[user]))

end_ = calculate(max('payroll'[date]),ALLEXCEPT('payroll','payroll'[user]))

Then you could calculate the weeks between start date and end date by using datediff() function.

weeks_ = datediff([start_],[end_ ],week)

 

Best Regards,

Jay

Anonymous
Not applicable

Thanks for the reply, your solution would only work if the people worked in continuous weeks without any weeks off.

Hi @Anonymous

 

Can you please share a mockup data or sample of your PBIX file. You can use a onedrive, google drive, we transfer or similar link to upload your files.

If the information is sensitive please share it trough private message.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



MFelix
Super User
Super User

Hi @Anonymous ,

 

Altough your explanation is complete has you can imagine redoing your model based on images only is very complicated can you please share a mockup data or sample of your PBIX file. You can use a onedrive, google drive, we transfer or similar link to upload your files.

If the information is sensitive please share it trough private message.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.