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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
maurcoll
Helper II
Helper II

sum not working correctly - maybe need selected value

Hi

I am trying to calculate the proportion of hours when we have to move people to a different store/dept due to staffing levels.
I have the number of hours that they were moved for and the total hours worked.
However when i do a sum of total hours worked it is giving me the total hours for everyone that has worked on that day not just the ones that were moved. In the below example it is giving me 1360 as total hours worked when it should be 69.5. I am only using Sum(hours worked) as the calculation, if i put into the filter total hours worked is not blank this works but i cant use this in a card visual ideally i want to do this in a measure if possible, not sure if it needs a selectedvalue or allselected.

DateTeamHours Moved LocationTotal Hours Worked
13/05/2024135.1551.5
13/05/2024231.518
Total 66.651360
  should be69.5

 

1 ACCEPTED SOLUTION

Actually, wrap this expression in SUMX. Does your model have a date table? If not, it's best practice to create a date table. In this example, the date table is 'Date' and has a relationship with the data (fact) table. The date field in the visual should be from the Date table.

 

Total Hours Worked =
SUMX (
    VALUES ( 'Date'[Date] ),
    IF ( NOT ISBLANK ( [Hours Moved Location] ), SUM ( Table[Hours Worked] ) )
)

 





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

Proud to be a Super User!




View solution in original post

3 REPLIES 3
v-heq-msft
Community Support
Community Support

Hi @maurcoll ,
Thanks for @DataInsights  reply.
Here some steps that I want to share, you can check them if they suitable for your requirement.
Here is my test data:

vheqmsft_0-1721889303074.png

Create a measure

Total Hours Worked = 
CALCULATE(
    SUM('Table'[Hours Worked]),
    FILTER(
        'Table',
        'Table'[Hours Moved Location] <> BLANK()
    )
)

Final output

vheqmsft_1-1721889360817.png

Best regards,
Albert He

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



DataInsights
Super User
Super User

@maurcoll,

 

One idea is to check the Hours Moved Location value: if it has a value then sum Hours Worked:

 

Total Hours Worked =
IF ( NOT ISBLANK ( [Hours Moved Location] ), SUM ( Table[Hours Worked] ) )

 





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

Proud to be a Super User!




Actually, wrap this expression in SUMX. Does your model have a date table? If not, it's best practice to create a date table. In this example, the date table is 'Date' and has a relationship with the data (fact) table. The date field in the visual should be from the Date table.

 

Total Hours Worked =
SUMX (
    VALUES ( 'Date'[Date] ),
    IF ( NOT ISBLANK ( [Hours Moved Location] ), SUM ( Table[Hours Worked] ) )
)

 





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

Proud to be a Super User!




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.