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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Basdo
Frequent Visitor

How to sum one column and take fix values of others

Hi,

 

I've got a table with the following structure:

DateWorker NameHoursContract Hours per DayWorkday
1.2.2022Tim281
1.2.2022Tim381
1.2.2022Tim481
1.2.2022Adam671
2.2.2022Tim881
2.2.2022Adam871
3.2.2022Adam470

 

I want to calculate overhours, i.e. hours worked above contract hours per day.

The column "Contract Hours per Day" has a fixed value for each worker, in this case Tim = 8, Adam = 7

The column "Workday" shows if the day in question is a workday (1) or not (0).

Both these columns have always the same entry for each Date, so they should NOT be summed up.

The workers can book several different entries per day, thats why the column "Hours" needs to be summed up.

 

The expected result of the calculation in this example is:

DateWorkerOverhours
1.2.2022Tim1
1.2.2022Adam-1
2.2.2022Tim0
2.2.2022Adam1
3.2.2022Tim4

 

 

I tried the following DAX expression:

Overhours = [Hours] - AVERAGE([Contract Hours per Day]*AVERAGE([Workday])

 

but the Average function always seems to take into account ALL table entries and not only those from the worker and date in question.

 

What would be a good way to solve this?

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Basdo , try a measure like

sumx(ADDCOLUMNS(summarize(Table, Table[Worker Name], Table[date]), "_hr" , sum(Table[Hours]), "_C", max(Table[Contract Hours per Day])), [_C] -[_hr])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
Basdo
Frequent Visitor

@amitchandak I've got another question. The solution you proposed works well for single table entries but the total calculation is still wrong. How to fix this?

@Basdo , Please share an example


Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Basdo
Frequent Visitor

Great amitchandak. Thank you very much.

amitchandak
Super User
Super User

@Basdo , try a measure like

sumx(ADDCOLUMNS(summarize(Table, Table[Worker Name], Table[date]), "_hr" , sum(Table[Hours]), "_C", max(Table[Contract Hours per Day])), [_C] -[_hr])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors