Forum Discussion
hungbm12
3 years agoRegular Visitor
Unexpected output - sumx
Hi everyone, I don't understand the result of the Total row (I expect it was 4) Here the data: Anyone help me?
- 3 years ago
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: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]))
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/
FreemanZ
Super User
3 years agohi 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