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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
SahityaYeruband
Helper II
Helper II

Measure used in Matrix doesn't show expected values in Totals

Hi All,

 

I have created a measure in Matrix, which works fine at the Month level but the total isn't populating correctly at the row level.

Eg : 

CountryDeptJan 2024Feb 2024March 2024Actual TotalExpected Total
USAHR  10<BLANK>10
USASales 4 44



Below is the measure : 

Total Hits Report page =

//Generate YYYYMM from selected Slicers
var _year = SELECTEDVALUE(Usage[Year_Index])
var _mth = SELECTEDVALUE(Usage[Month Name])
var _mth_num = maxx(FILTER((Usage), Usage[Month Name] = _mth), Usage[Month Num])
var _selected_date = 100*_year + _mth_num

//Get the required list of reports
var __Listofreports = CALCULATETABLE(VALUES(Usage[Report path]), Usage[Creation_YYYYMM] < _selected_date)


//Calculate Hits for the specific list of reports
var _hits = CALCULATE(SUM(Usage[Total Hits Monthly]), Usage[Report path] in __Listofreports)

var _hits1 = CALCULATE(SUMX(Usage, Usage[Total Hits Monthly]), Usage[Report path] in __Listofreports)

return
_hits1

Neither _hits nor _hits1 is showing expected values.
What is confusing is, total is showing correct values for some and blanks for other, not sure what is happening.

 

Thanks in advance for your help.

2 ACCEPTED SOLUTIONS
BeaBF
Super User
Super User

@SahityaYeruband Hi! Try with:

Total Hits Report page =
VAR _year = SELECTEDVALUE(Usage[Year_Index])
VAR _mth = SELECTEDVALUE(Usage[Month Name])
VAR _mth_num = MAXX(FILTER(Usage, Usage[Month Name] = _mth), Usage[Month Num])
VAR _selected_date = 100 * _year + _mth_num

// Handle totals calculation explicitly
VAR _isTotal = ISINSCOPE(Usage[Month Name]) = FALSE

// Get the required list of reports
VAR __Listofreports =
CALCULATETABLE(
VALUES(Usage[Report path]),
Usage[Creation_YYYYMM] < _selected_date
)

// Calculate Hits for the specific list of reports
VAR _hits =
CALCULATE(
SUM(Usage[Total Hits Monthly]),
Usage[Report path] IN __Listofreports
)

// If in Total row, calculate without relying on Month Name
RETURN
IF(
_isTotal,
CALCULATE(
SUM(Usage[Total Hits Monthly]),
Usage[Creation_YYYYMM] < MAX(Usage[Creation_YYYYMM])
),
_hits
)

 

BBF

View solution in original post

rohit1991
Super User
Super User

Hi @SahityaYeruband ,
The issue is likely due to how Power BI handles totals in measures within a Matrix visualization. Suggested Fix

Try modifying your measure to use SUMX with an iterating table to ensure row-level calculations roll up correctly:

Total Hits Report page = 
// Generate YYYYMM from selected Slicers
VAR _year = SELECTEDVALUE(Usage[Year_Index])
VAR _mth = SELECTEDVALUE(Usage[Month Name])
VAR _mth_num = MAXX(FILTER(Usage, Usage[Month Name] = _mth), Usage[Month Num])
VAR _selected_date = 100 * _year + _mth_num

// Get the required list of reports
VAR __Listofreports = 
    CALCULATETABLE(
        VALUES(Usage[Report path]), 
        Usage[Creation_YYYYMM] < _selected_date
    )

// Calculate Hits for the specific list of reports using SUMX for iteration
VAR _hits = 
    SUMX(
        FILTER(Usage, Usage[Report path] IN __Listofreports),
        Usage[Total Hits Monthly]
    )

RETURN _hits






Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

View solution in original post

2 REPLIES 2
rohit1991
Super User
Super User

Hi @SahityaYeruband ,
The issue is likely due to how Power BI handles totals in measures within a Matrix visualization. Suggested Fix

Try modifying your measure to use SUMX with an iterating table to ensure row-level calculations roll up correctly:

Total Hits Report page = 
// Generate YYYYMM from selected Slicers
VAR _year = SELECTEDVALUE(Usage[Year_Index])
VAR _mth = SELECTEDVALUE(Usage[Month Name])
VAR _mth_num = MAXX(FILTER(Usage, Usage[Month Name] = _mth), Usage[Month Num])
VAR _selected_date = 100 * _year + _mth_num

// Get the required list of reports
VAR __Listofreports = 
    CALCULATETABLE(
        VALUES(Usage[Report path]), 
        Usage[Creation_YYYYMM] < _selected_date
    )

// Calculate Hits for the specific list of reports using SUMX for iteration
VAR _hits = 
    SUMX(
        FILTER(Usage, Usage[Report path] IN __Listofreports),
        Usage[Total Hits Monthly]
    )

RETURN _hits






Did it work? ✔ Give a Kudo • Mark as Solution – help others too!
BeaBF
Super User
Super User

@SahityaYeruband Hi! Try with:

Total Hits Report page =
VAR _year = SELECTEDVALUE(Usage[Year_Index])
VAR _mth = SELECTEDVALUE(Usage[Month Name])
VAR _mth_num = MAXX(FILTER(Usage, Usage[Month Name] = _mth), Usage[Month Num])
VAR _selected_date = 100 * _year + _mth_num

// Handle totals calculation explicitly
VAR _isTotal = ISINSCOPE(Usage[Month Name]) = FALSE

// Get the required list of reports
VAR __Listofreports =
CALCULATETABLE(
VALUES(Usage[Report path]),
Usage[Creation_YYYYMM] < _selected_date
)

// Calculate Hits for the specific list of reports
VAR _hits =
CALCULATE(
SUM(Usage[Total Hits Monthly]),
Usage[Report path] IN __Listofreports
)

// If in Total row, calculate without relying on Month Name
RETURN
IF(
_isTotal,
CALCULATE(
SUM(Usage[Total Hits Monthly]),
Usage[Creation_YYYYMM] < MAX(Usage[Creation_YYYYMM])
),
_hits
)

 

BBF

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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