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
TJI7746
Regular Visitor

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) 

HC Previous Quarter =

VAR _maxdate = MAX(Headcount[Date])

VAR _prevq = CALCULATE(MAX(Headcount[Date]),FILTER(ALL('Headcount'),Headcount[Date]<_maxdate))

RETURN CALCULATE([Headcount],'Calendar'[Date] = _prevq)
 
In my table I have added row subtotals from the visualisation menu, but they are not correct. Can someone help me as I am going Crazy.  Sometimes the values show correctly but when i add more filters that's when the subtotals become incorrect.
 
TJI7746_0-1732549472300.png

 

 
4 REPLIES 4
FreemanZ
Super User
Super User

hi @TJI7746 , 

 

try like:

1) HC Current Quarter =
VAR _maxdate = MAX('Headcount'[Date])
RETURN 
SUMX(
    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))
RETURN 
SUMX(
    VALUES(headcount[gender]),
    CALCULATE([Headcount],'Calendar'[Date] = _prevq)
)

BeaBF
Super User
Super 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

This didn't work unfortunately 😞

Anonymous
Not 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 Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.