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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Sumx returning incorrect result

Measure ShiftSum_First wasn't returning the correct result, when digging into I found that a variable within the measure was returning some unexpected results. See image below, Work Center 'A' in this case works as expected - it gets the sum of Seconds that would have resulted during the First Shift (7am to 3pm) while the machine is 'Running', adds up correctly to 26,661 seconds. Work Center B in this case operates correctly at row level, but sum it becomes -146,326? Why isn't it 26,474?


I've provided two measures below, ShiftStrt & ShiftEnd are referenced in my ShiftSum measure. ShiftStrt and ShiftEnd are exactly the same except one references column 'StartDate' the other references 'EndDate'.

 

There's only one outside filter influence on Start Date, shown below. 

 

ShiftStrt =

var TimeVal = TIME(HOUR(max(MachineBoxInfo[Startdate])),MINUTE(max(MachineBoxInfo[Startdate])),0)
Return
IF(AND(TimeVal>=TIME(7,0,0),TimeVal<TIME(15,0,0)),1,
IF(AND(TimeVal>=TIME(15,0,0),TimeVal<TIME(23,0,0)),2,
IF(OR(TimeVal>=TIME(23,0,0),TimeVal<TIME(7,0,0)),3,blank())))

 

 

ShiftSum_First =
var RowStartTime = DATE(year(max(MachineBoxInfo[Startdate])),month(max(MachineBoxInfo[Startdate])),Day(max(MachineBoxInfo[Startdate])))+TIME(7,0,0)
var RowEndTime = DATE(year(max(MachineBoxInfo[Startdate])),month(max(MachineBoxInfo[Startdate])),Day(max(MachineBoxInfo[Startdate])))+TIME(15,0,0)
 
var SecsCarryOver = CALCULATE(SUMX(FILTER(MachineBoxInfo,AND(OR(AND([ShiftStrt]=1,[ShiftEnd]=2),AND([ShiftStrt]=3,[ShiftEnd]=1)),MachineBoxInfo[statedesc]="Running")),
IF([ShiftStrt]=3,Datediff(RowStartTime,MachineBoxInfo[Enddate],Second),
IF([ShiftStrt]=1,DATEDIFF(MachineBoxInfo[Startdate],RowEndTime,second),blank()))))
 
var SecsRun = CALCULATE(SUMX(MachineBoxInfo,
IF(AND([ShiftStrt]=1,AND([ShiftEnd]=1,MachineBoxInfo[statedesc]="Running")),MachineBoxInfo[seconds],blank())))

Return
SecsCarryOver
 
161462cc_0-1633437703717.png

 

161462cc_1-1633437735289.png

 

3 REPLIES 3
Anonymous
Not applicable

Hi  @Anonymous ,
You can create a measure:

Place it in the table and compare with [ShiftSum_First], and find whether total is displayed correctly:

Measure=
VAR __table = SUMMARIZE(MachineBoxInfo, MachineBoxInfo[Startdate] ,"__value", [ShiftSum_First])
RETURN
IF(HASONEVALUE(MachineBoxInfo[Startdate]), [ShiftSum_First],SUMX(__table,[__value]))

 

Best Regards,

Liu Yang

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

amitchandak
Super User
Super User

@Anonymous , we need force a row context from visual example

 


var SecsCarryOver = CALCULATE(SUMX(values(MachineBoxInfo[workcenter]) ,
IF([ShiftStrt]=3,Datediff(RowStartTime,MachineBoxInfo[Enddate],Second),
IF([ShiftStrt]=1,DATEDIFF(MachineBoxInfo[Startdate],RowEndTime,second),blank()))), FILTER(MachineBoxInfo,AND(OR(AND([ShiftStrt]=1,[ShiftEnd]=2),AND([ShiftStrt]=3,[ShiftEnd]=1)),MachineBoxInfo[statedesc]="Running")))

 

 

refer if needed


var SecsCarryOver = CALCULATE(SUMX(values(MachineBoxInfo[workcenter]) ,
IF([ShiftStrt]=3,Datediff(RowStartTime,MachineBoxInfo[Enddate],Second),
IF([ShiftStrt]=1,DATEDIFF(MachineBoxInfo[Startdate],RowEndTime,second),blank()))), FILTER(MachineBoxInfo,AND(OR(AND([ShiftStrt]=1,[ShiftEnd]=2),AND([ShiftStrt]=3,[ShiftEnd]=1)),MachineBoxInfo[statedesc]="Running")))

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
Anonymous
Not applicable

@amitchandak  Thank you for your response, unfortunately that didn't work. When using the Values on the WorkCenter I cannot simply refer to the StartDate and EndDate columns, as they aren't in the input table. I used max() to refer to them, and it worked at the row level but totals didn't come through correctly.  I know I can add another measure to handle this with HASONEVALUE on the total row, but I'd like to accomplish it in one measure if possible. 

 

161462cc_0-1633442148195.png

161462cc_1-1633442176068.png

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors