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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Sum two elements in the same column with a condition

DBB_0-1675178477898.png

Hello,

I want to do the following:

At my company there are two shifts in a day, and the data is uploaded when each shift ends.

So I have two rows per day.

I need to create two columns (as you can see in red) that sum the hours worked and not worked per day.

The function has to take into account the day, if it is the same, it must add the two values of hours

 

Can anybody help me?

1 ACCEPTED SOLUTION

hi @Anonymous 

try like:

Hs worked/day = 
VAR _worked =
SUMX(
    FILTER(
        TableName,
        TableName[Date]=EARLIER(TableName[Date])
    ),
    TableName[Worked]
)
RETURN
IF([Shift]="B", _worked)

Hs unworked/day = 
VAR _unworked=
SUMX(
    FILTER(
        TableName,
        TableName[Date]=EARLIER(TableName[Date])
    ),
    TableName[Unworked]
)
RETURN
IF([Shift]="B",_unworked)

it worked like this:

FreemanZ_0-1675259202082.png

 

View solution in original post

3 REPLIES 3
FreemanZ
Super User
Super User

hi @Anonymous 

 

It is more advisable to do with table visuals, like this:

FreemanZ_0-1675218697391.png

 

2 reminders: 1) avoid the date hierarchy, 2) choose SUM for the two hour columns.

Anonymous
Not applicable

Hello, thank you for the reply.

The problem with that is I need to make other functions after with the values of hours per day. So I need to do it in DAX.

hi @Anonymous 

try like:

Hs worked/day = 
VAR _worked =
SUMX(
    FILTER(
        TableName,
        TableName[Date]=EARLIER(TableName[Date])
    ),
    TableName[Worked]
)
RETURN
IF([Shift]="B", _worked)

Hs unworked/day = 
VAR _unworked=
SUMX(
    FILTER(
        TableName,
        TableName[Date]=EARLIER(TableName[Date])
    ),
    TableName[Unworked]
)
RETURN
IF([Shift]="B",_unworked)

it worked like this:

FreemanZ_0-1675259202082.png

 

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.