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
Coryanthony
Helper III
Helper III

Sum hours based on day, then create new column with IF function

Hello, 

I want to sum up hours worked base on day, then create a column ($Allowed) base on the sum of hours.

 

$ Allow = CALCULATE(SUM(Timesheet[Number (unit)]), IF(Timesheet[Day of Week] >=0 && Timesheet[Day of Week] <=4 && Timesheet[Number (unit)] >10, 20,0))
 
Capture.JPG
1 ACCEPTED SOLUTION

Hi @Coryanthony ,

 

This is due to the nature of calculated columns, and you can create a table visual to show.

Picture1.png

You can also create a measure.

measure_Allowed = 
var _sum = CALCULATE(SUM('Table'[number (unit)]),FILTER(ALLEXCEPT('Table','Table'[employee id],'Table'[date]),'Table'[number (unit)]))
return 
IF(_sum>10&&max('Table'[Day of Week])>=0&&MAX('Table'[Day of Week])<=4,20,0)

Picture2.png

Please refer to my PBIX file.

 

Best Regards,

Neeko Tang

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

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Hi,

Show the expected result very clearly.  Share the download link of the PBI file.


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

thank you for your input Ashish. I am learning more about community.powerbi. 

 

If you have any suggestion, please feel free to share. Thank you

v-tangjie-msft
Community Support
Community Support

Hi @Coryanthony ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data.  

vtangjiemsft_0-1671760093189.png

(2) We can create a calculated column.

$Allowed = 
var _sum = CALCULATE(SUM('Table'[number (unit)]),FILTER(ALLEXCEPT('Table','Table'[employee id],'Table'[date]),'Table'[number (unit)]))
return 
IF(_sum>10&&'Table'[Day of Week]>=0&&'Table'[Day of Week]<=4,20,0)

(3) Then the result is as follows.

vtangjiemsft_1-1671760366580.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

Hi Neeko,

Thank you so much for your time and well written explanation, it honestly means a lot. 

Your solution worked! Only issue - its currently allowing $20 multiple times for same day. If you look at the snippet you provided for date "2022-12-13", it duplicated the $20. I assume the only work around is to delete the duplicates? 

 

I am faily new to power BI, but doing my very best to learn. If there are any tools/courses/classes you can suggest, that would be extremely awesome. If you also know of any personal tutors, please please share.

 

Thank you.

Hi @Coryanthony ,

 

This is due to the nature of calculated columns, and you can create a table visual to show.

Picture1.png

You can also create a measure.

measure_Allowed = 
var _sum = CALCULATE(SUM('Table'[number (unit)]),FILTER(ALLEXCEPT('Table','Table'[employee id],'Table'[date]),'Table'[number (unit)]))
return 
IF(_sum>10&&max('Table'[Day of Week])>=0&&MAX('Table'[Day of Week])<=4,20,0)

Picture2.png

Please refer to my PBIX file.

 

Best Regards,

Neeko Tang

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

one last thing Neeko, if i need to add more IF/logical statement to this such as, "

IF(_sum>=5 <8 &&'Timesheet'[Day of Week]>=5 ,15,0)
IF(_sum>=8 &&'Timesheet'[Day of Week]>=5 ,30,0)" 
These statement simply allow $15 if worked 5-7.999 hours on weekend. The other allows $30 if 8+ hrs are worked on the weekend.
 
I will need to add another logical statement for holiday days. So If sum is >4 and on 12/25/2022 then $30.
 
Thank you again.
Coryanthony
Helper III
Helper III

Please help if all possible. Thank you 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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