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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
hungbm12
Regular Visitor

Unexpected output - sumx

Hi everyone,

I don't understand the result of the Total row (I expect it was 4)

hungbm12_1-1671781729654.png

Here the data:

hungbm12_2-1671781861120.png

 

Anyone help me?

 

 

 

1 ACCEPTED SOLUTION
ValtteriN
Super User
Super User

Hi,

I recommend reading this article by SQLBI about the total row: https://www.sqlbi.com/articles/why-power-bi-totals-might-seem-inaccurate/

The behaviour of totals is a bit wonky in Power BI.

For a solution try something like this:

ValtteriN_0-1671784671355.png

Dax:

Measure 29 =
var _mdate = CALCULATE(MAX('Table (18)'[date]),ALL('Table (18)'[date])) return

CALCULATE(SUM('Table (18)'[value]),'Table (18)'[date]=_mdate,ALL('Table (18)'[date]))

ValtteriN_1-1671784976096.png

 

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/




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

Proud to be a Super User!




View solution in original post

4 REPLIES 4
FreemanZ
Super User
Super User

hi @hungbm12 

Trying to understand how your code works. It shall be executed like this:

measure 3 = 
SUMX(
    DISTINCT(Sheet1[category]), //1.scans category A then B
    CALCULATE(  //2.convert row context A(B) to filter context A(B)
        SUM( Sheet1[value]), //7. it get 2+2 when scanning A in step 1 and another 2+2 in scanning B, so comes 8
        FILTER( // 6. filter context A(B) is replaced by the outcome of FILTER, which is two 24 Dec rows.
            Sheet1,     //3.scan the original Sheet1 
            VAR _maxdate = MAX(Sheet1[Date])  // 4. _maxdate equals 24 Dec
            RETURN [date]=_maxdate   //5. filter in two rows on 24 Dec.
        )
    )
)

 

p.s.

[date]=MAX(Sheet1[Date])

is a misleading syntax sugar and thus extended to:

VAR _maxdate = MAX(Sheet1[Date]) 
RETURN [date]=_maxdate

FreemanZ
Super User
Super User

hi @hungbm12 

 

try like:

measure2 = COUNTROWS(Sheet1)
 
it worked like this:
FreemanZ_0-1671784986202.png

 

ValtteriN
Super User
Super User

Hi,

I recommend reading this article by SQLBI about the total row: https://www.sqlbi.com/articles/why-power-bi-totals-might-seem-inaccurate/

The behaviour of totals is a bit wonky in Power BI.

For a solution try something like this:

ValtteriN_0-1671784671355.png

Dax:

Measure 29 =
var _mdate = CALCULATE(MAX('Table (18)'[date]),ALL('Table (18)'[date])) return

CALCULATE(SUM('Table (18)'[value]),'Table (18)'[date]=_mdate,ALL('Table (18)'[date]))

ValtteriN_1-1671784976096.png

 

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/




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

Proud to be a Super User!




I'm sorry but if I changed the 4th row to December 28th, Total row = 2 (not as I expect). I expect it get the newest value of each Category and return 4

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.