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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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