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
catnapwat
Helper I
Helper I

Incorrect measure totals despite using Summarize workaround

I'm struggling with measure totals despite using recommended ways around the problem. I need to total the hours logged across selected staff members and date range.

My data looks like this  (some values removed).

My measure is:

 

StandardHours =
VAR StandardHours =COUNTROWS(DISTINCT('Timesheet Data'[Date]))*7.5
VAR StandardHoursTotal = SUMMARIZE('Timesheet Data','Timesheet Data'[Staff Name],"StddHrs", StandardHours)
RETURN
IF(
HASONEFILTER('Timesheet Data'[Staff Name]),
StandardHours,
SUMX(StandardHoursTotal,[StddHrs])
)

 

Output is coming out at:

Staff NameStandard Hours
A37.5
B37.5
C22.5
D

30.0

Total150

 

The total should be 127.5. The individual staff numbers are correct.

 

It seems DAX is just adding 37.5 (i.e. standard working week in hours) for each member of staff, regardless of how many actual days are logged in the fact table. I'm counting the rows using DISTINCT to find the number of days logged in that week.

The table is filtered on a slicer to "last 1 weeks (calendar)" but it doesn't make any difference if I remove the slicer- the total is still incorrect.

Any help much appreciated. Where am I going wrong?

2 REPLIES 2
Greg_Deckler
Super User
Super User

@catnapwat - I usually do this as 2 separate measures as here: This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_DecklerThanks- I actually have both of your useful guides open at the moment, but I still couldn't figure it out.

 

A user on Reddit has cracked it though- and noted that the variable didn't have any filtering applied as the summary table was being built. I had assumed the filtering was based on where the variable was used rather than where it is defined, which was incorrect. So they suggested I recalculate the variable inside the Summarize which filters it correctly:

 

StandardHours = 
VAR StandardHours =COUNTROWS(DISTINCT('Timesheet Data'[Date]))*7.5
VAR StandardHoursTotal = SUMMARIZE('Timesheet Data','Timesheet Data'[Staff Name],"StddHrs", 
    SUMX(
        VALUES('Timesheet Data'[Staff Name]),
        COUNTROWS(DISTINCT('Timesheet Data'[Date]))*7.5)
        )
RETURN
IF(
    HASONEFILTER('Timesheet Data'[Staff Name]),
    StandardHours,
    SUMX(StandardHoursTotal,[StddHrs])
) 

 Now I just have a bunch more measures to correct...

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.