Forum Discussion
DAX Help with Row totals not adding correctly.
Hi everyone
I have the following 2 DAX formulas
1) HC Current Quarter =
VAR _maxdate = MAX('Headcount'[Date])
RETURN CALCULATE([Headcount],'Calendar'[Date] = _maxdate)
And
2)
4 Replies
- BeaBFSuper User
TJI7746 Hi! Try with:
HC Current Quarter =
VAR _maxdate = MAX('Headcount'[Date])
RETURN
IF(
HASONEVALUE('Calendar'[Date]),
CALCULATE([Headcount], 'Calendar'[Date] = _maxdate),
SUMX(
SUMMARIZE(
'Headcount',
'Calendar'[Date],
"HC", CALCULATE([Headcount], 'Calendar'[Date] = _maxdate)
),
[HC]
)
)HC Previous Quarter =
VAR _maxdate = MAX('Headcount'[Date])
VAR _prevq = CALCULATE(
MAX(Headcount[Date]),
FILTER(ALL('Headcount'), Headcount[Date] < _maxdate)
)
RETURN
IF(
HASONEVALUE('Calendar'[Date]),
CALCULATE([Headcount], 'Calendar'[Date] = _prevq),
SUMX(
SUMMARIZE(
'Headcount',
'Calendar'[Date],
"HC", CALCULATE([Headcount], 'Calendar'[Date] = _prevq)
),
[HC]
)
)BBF
- TJI7746Regular Visitor
This didn't work unfortunately 😞
- AnonymousNot applicable
Hi TJI7746 ,
I think you can try SUMX() function to sum the measures to get correct result in subtotal.
HC Current Quarter (New) = SUMX(SUMMARIZE(Headcount,Headcount[Area],Headcount[SF Legal Gender]),[HC Current Quarter])HC Previous Quarter (New) = SUMX(SUMMARIZE(Headcount,Headcount[Area],Headcount[SF Legal Gender]),[HC Previous Quarter])If this reply still couldn't help you solve your issue, please share a sample file with us.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- FreemanZSuper User
hi TJI7746 ,
try like:
1) HC Current Quarter =VAR _maxdate = MAX('Headcount'[Date])RETURNSUMX(VALUES(headcount[gender]),CALCULATE([Headcount],'Calendar'[Date] = _maxdate))HC Previous Quarter =VAR _maxdate = MAX(Headcount[Date])VAR _prevq = CALCULATE(MAX(Headcount[Date]),FILTER(ALL('Headcount'),Headcount[Date]<_maxdate))RETURNSUMX(VALUES(headcount[gender]),CALCULATE([Headcount],'Calendar'[Date] = _prevq))