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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
icbd
Helper I
Helper I

Weird behaviour with SUMX and date filters

I'm having a very weird issue with SUMX and date filters.

 

The current formula I am using is as follows:

 

 

RunTimeTest2 = SUMX('Date', MAX(DataPartCell1[ShiftHour]) - MIN(DataPartCell1[ShiftHour]))

 

 Where 'Date' is a calendar table marked as such, and the [ShiftHour] is the hour converted as decimal.
 
What I am trying to achieve is somewhat obvious from the formula, I want to subtract the max value and the minimum value for each selected date.
 
This works perfect for a single day, but as soon as I select more than one day in my date filter, SUMX calculates the first day, and multiplies that by the number of days selected, ignoring all subsequent days.
 
When I put the measure into a matrix, it show up correctly for each date, with the total being completely off.
 
Here is an example of what I mean:
icbd_0-1643562981884.png

The values shown (22.92 and 13.17) are correct, the total is not. I have 2 days selected so the total is 2022-01-27*2 = 22.92*2 = 45.83

 

How can I fix this? I'm kind of stumped here.

1 ACCEPTED SOLUTION
icbd
Helper I
Helper I

I was able to solve this following this guide:

https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

 

Using two measures, the first one being:

RunTimeTest2 = SUMX('Date', MAX(DataPartCell1[ShiftHour]) - MIN(DataPartCell1[ShiftHour]))

 

The second one being:

 

ActualRuntime = 
VAR __table = SUMMARIZE('Date',[Date],"__value",[RunTimeTest2])
RETURN
IF(HASONEVALUE('Date'[Date]),[RunTimeTest2],SUMX(__table,[__value]))

View solution in original post

2 REPLIES 2
ValtteriN
Super User
Super User

Hi,

This is a common issue and it has to do with the way totals work on visualizations. I recommend cheking this post by SQLBI to understand what is going on: https://www.sqlbi.com/articles/summing-values-for-the-total/





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

Proud to be a Super User!




icbd
Helper I
Helper I

I was able to solve this following this guide:

https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

 

Using two measures, the first one being:

RunTimeTest2 = SUMX('Date', MAX(DataPartCell1[ShiftHour]) - MIN(DataPartCell1[ShiftHour]))

 

The second one being:

 

ActualRuntime = 
VAR __table = SUMMARIZE('Date',[Date],"__value",[RunTimeTest2])
RETURN
IF(HASONEVALUE('Date'[Date]),[RunTimeTest2],SUMX(__table,[__value]))

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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