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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
otto-user101
Frequent Visitor

Measure returning correct total but row value is incorrect

I have a dataset with multiyear data. See sample below.

YearRegionEmployeesPrimary Key
2020WestEmployee1 2020WestEmployee1
2020EastEmployee2 2020EastEmployee2
2020WestEmployee3 2020WestEmployee3
2020SouthEmployee4 2020SouthEmployee4
2020SouthEmployee5 2020SouthEmployee5
2021NorthEmployee6 2021NorthEmployee6
2021NorthEmployee7 2021NorthEmployee7
2021EastEmployee8 2021EastEmployee8
2021WestEmployee9 2021WestEmployee9
2021SouthEmployee10 2021SouthEmployee10
2022NorthEmployee11 2022NorthEmployee11
2022NorthEmployee12 2022NorthEmployee12
2022EastEmployee13 2022EastEmployee13
2022WestEmployee14 2022WestEmployee14
2022SouthEmployee15 2022SouthEmployee15
2022WestEmployee16 2022WestEmployee16
2023NorthEmployee17 2023NorthEmployee17
2023EastEmployee18 2023EastEmployee18
2023WestEmployee19 2023WestEmployee19
2023SouthEmployee20 2023SouthEmployee20
2023WestEmployee21 2023WestEmployee21
2024NorthEmployee22 2024NorthEmployee22
2024EastEmployee23 2024EastEmployee23
2024WestEmployee24 2024WestEmployee24
2024SouthEmployee25 2024SouthEmployee25
2024EastEmployee26 2024EastEmployee26
2024NorthEmployee27 2024NorthEmployee27

 

With this dataset, I have a matrix viz that pulls in Region for Rows; Year in columns; measure (count-historical = distinctcount('data'[primary key]). This matrix is formatted as shown in the table below presenting the count of employees by year/region.

 

Matrix A

Region20202021202220232024
North02212
South21111
East11112
West21221
Total55656

 

No issues here. Now, I have another matrix with regions in Rows and a measure in Values. There's a year slicer on this page that allows filtering by a range of years. I would like for the measure to pull in the employee count for the min(year) - e.g., if the slicer is set to 2020-2022, the values for 2020 will populate. The dax for this measure is: 

Range Min =
var _minyear = MIN('data'[Year])
var _minval = IF(
ISBLANK(CALCULATE(COUNT('data'[PrimaryKey]), YEAR('data'[Year])=year(_minyear))), 0,CALCULATE(COUNT('data'[Primary Key]),YEAR('data'[Year])=year(_minyear)))
)
return
_minval

 

The issue is that when the calculated value is 0, the measure populates a value from an adjacent year and not "0", but the total is correct... Does anyone have insight as to why this is happening?

 

RegionMinMax
North2 (should be 0)2
South21
East11
West22
Total56
2 REPLIES 2
otto-user101
Frequent Visitor

Hi @v-weiyan1-msft thanks for your response. The dax you provided for Min (and Max) populates 0 when the count is blank. 

There's something I didn't include in my initial post - the regions are grouped and with the new dax, the subtotals and totals are inaccurate, and I'm looking to achieve what's shown in the table below. 

Region202020212022
Group A233
  North022
  South211
Group B323
  East111
  West212
Total556

 

Can you assist with this? Much appreciated!

v-weiyan1-msft
Community Support
Community Support

Hi @otto-user101 ,

 

Based on the example and description you provided, please try code as below to create measure.

 

Min = 
VAR _mintyear =
    MINX ( ALLSELECTED('Table'),'Table'[Year] )
VAR _count =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Primary Key] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Region] = MAX ( 'Table'[Region] )
                && 'Table'[Year] = _mintyear
        )
    )
RETURN
    IF ( _count = BLANK (), 0, _count )
Min_Result = 
IF (
    HASONEVALUE ( 'Table'[Region] ),
    [Min],
    SUMX ( VALUES ( 'Table'[Region] ), [Min] )
)
Max = 
VAR _maxyear =
    MAXX ( ALLSELECTED('Table'),'Table'[Year] )
VAR _count =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Primary Key] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Region] = MAX ( 'Table'[Region] )
                && 'Table'[Year] = _maxyear
        )
    )
RETURN
    IF ( _count = BLANK (), 0, _count )
Max_Result = 
IF (
    HASONEVALUE ( 'Table'[Region] ),
    [Max],
    SUMX ( VALUES ( 'Table'[Region] ), [Max] )
)

 

When the slicer is set to 2020-2022, Result is as below.

vweiyan1msft_0-1709889458423.png


Best Regards,
Yulia Yan


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

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Solution Authors