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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
paul_luvaglia
New Member

Calculated Column With Department with Highest Sum of Hours

Apologies for the slightly confusing thread title but struggling to summarise what I`m trying to do

 

I have 2 tables.

Table 1 contains 2 columns Employee Name & Date

EmployeeDate
Dave13/02/2022
Dave14/02/2022
Dave15/02/2022
Pete13/02/2022
Pete14/02/2022
Pete15/02/2022
Jeff13/02/2022
Jeff14/02/2022
Jeff15/02/2022

 

Table 2 contains a list of jobs that each employee has booked onto for each date. it includes the Department that the employee worked in for that job

EntryNameDateJob NoDeptHours
1Dave14/02/202221001Packing          1.00
2Dave13/02/202221002Packing          8.00
3Jeff14/02/202221003Packing          6.00
4Pete14/02/202221004Welding          8.00
5Dave14/02/202221005Welding          0.50
6Jeff13/02/202221006Welding          8.00
7Dave14/02/202221007Welding          1.00
8Pete14/02/202221008Packing          8.00
9Pete15/02/202221009Packing          8.00
10Dave 14/02/202221010Welding          1.00
11Dave14/02/202221011Packing          1.00

 

I would like a calculated column in Table1 that gives the department that the employee spent most of their time in for that day.

So in the example for Dave on the 14/02/2022 i would like to see "Welding", as he spent 2.5 hours in welding but only 2 hours in Packing on that day.

 

Thanks for your help

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @paul_luvaglia 

 

You can try the following methods.

Table 2: Column

Sum = 
CALCULATE (
    SUM ( 'Table 2'[Hours] ),
    FILTER (
        'Table 2',
        [Name] = EARLIER ( 'Table 2'[Name] )
            && [Date] = EARLIER ( 'Table 2'[Date] )
            && [Dept] = EARLIER ( 'Table 2'[Dept] )
    )
)
Results = 
IF (
    [Sum]
        = CALCULATE (
            MAX ( 'Table 2'[Sum] ),
            FILTER (
                'Table 2',
                [Name] = EARLIER ( 'Table 2'[Name] )
                    && [Date] = EARLIER ( 'Table 2'[Date] )
            )
        ),
    [Dept]
)

vzhangti_0-1651210857042.png

Table 1: Column

DEPT = 
CALCULATE (
    MAX ( 'Table 2'[Results] ),
    FILTER (
        'Table 2',
        [Date] = EARLIER ( 'Table 1'[Date] )
            && [Name] = EARLIER ( 'Table 1'[Employee] )
    )
)

vzhangti_1-1651210896966.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

3 REPLIES 3
v-zhangti
Community Support
Community Support

Hi, @paul_luvaglia 

 

You can try the following methods.

Table 2: Column

Sum = 
CALCULATE (
    SUM ( 'Table 2'[Hours] ),
    FILTER (
        'Table 2',
        [Name] = EARLIER ( 'Table 2'[Name] )
            && [Date] = EARLIER ( 'Table 2'[Date] )
            && [Dept] = EARLIER ( 'Table 2'[Dept] )
    )
)
Results = 
IF (
    [Sum]
        = CALCULATE (
            MAX ( 'Table 2'[Sum] ),
            FILTER (
                'Table 2',
                [Name] = EARLIER ( 'Table 2'[Name] )
                    && [Date] = EARLIER ( 'Table 2'[Date] )
            )
        ),
    [Dept]
)

vzhangti_0-1651210857042.png

Table 1: Column

DEPT = 
CALCULATE (
    MAX ( 'Table 2'[Results] ),
    FILTER (
        'Table 2',
        [Date] = EARLIER ( 'Table 1'[Date] )
            && [Name] = EARLIER ( 'Table 1'[Employee] )
    )
)

vzhangti_1-1651210896966.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

paul_luvaglia
New Member

Amazing, thank you. 

Greg_Deckler
Community Champion
Community Champion

@paul_luvaglia Try this in table 1:

Column =
  VAR __Employee = 'Table1'[Employee]
  VAR __Date = 'Table1'[Date]
  VAR __Table = SUMMARIZE(FILTER('Table2',[Employee] = __Employee && [Date] = __Date),[Dept],"Hours",SUM('Table2'[Hours]))
  VAR __Hours = MAXX(__Table,[Hours])
RETURN
  MAXX(FILTER(__Table,[Hours] = __Hours),[Dept])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.