cancel
Showing results for
Did you mean:
Post Patron

## how to correct measure total for matrix

I am running into the classic "total row does not agree with sum of detail rows" problem.

I have a type 2 employee schedule dimension table with grain:

employee version + week

I have a measure defined as:

Total Sales =

CALCULATE(

SUM('Fact Sales'[Amount])

,'Dimension Employee Schedule'[Category] = "A"

)

I have a matrix visual with row fields:

[Group] \ [Type]

To correct the Total row in this matrix, I have implemented the following measure:

Total Sales by group and type =
VAR __table =
SUMMARIZE(

'Dimension Employee Schedule'

,'Dimension Employeee Schedule'[Group]

,'Dimension Employee Schedule'[Type]

,"__value"

,[Total Sales]

)

RETURN

IF(

HASONEVALUE('Dimension Employee Schedule'[Group])

,[Total Sales]

,SUMX(

__table

,[__value]

)

)

As far as I know, this is the correct pattern to follow for Total rows.  However, my Total row value isn't the sum of the detail rows.  How do I correct this measure?

1 ACCEPTED SOLUTION

Accepted Solutions
Microsoft

Hi  @qubit813,

Here are the steps you can follow：

1. According to your description, the total may fail due to whether Type is multiple values.

Returns TRUE when the context for columnName has been filtered down to one distinct value only,Otherwise is FALSE.

As shown below:

When a value is selected, it is displayed as True.

When one or more values are selected, it is displayed as False.

2. For the problem of making the head office and the details the same, we can not only use HASONEVALUE, but also use HASONEFILTER function.

The difference between the two functions can be viewed at this link

https://docs.microsoft.com/en-us/dax/hasonefilter-function-dax

3.  In this regard, I created data to simulate the use of two functions HASONEVALUE and HASONEFILTER for you.

Data created:

Created measure:

``````Measure =
IF(SUM('Dimension Employee Schedule'[Amount])<300,0,SUM('Dimension Employee Schedule'[Amount]))

HASONEFILTER =
IF(HASONEFILTER('Dimension Employee Schedule'[Date]),
IF(SUM('Dimension Employee Schedule'[Amount])<300,0,SUM('Dimension Employee Schedule'[Amount])),
SUMX(FILTER('Dimension Employee Schedule',[Amount]>300),[Amount])
)

HASONEVALUE =
var _new=SUMMARIZE('Dimension Employee Schedule','Dimension Employee Schedule'[Date],"_value",[Measure])
return IF(HASONEVALUE('Dimension Employee Schedule'[Date]),[Measure],SUMX(_new,[_value]))``````

4. Result.

If this response does not meet your needs, can you provide a copy of sample data.

Best Regards,

Liu Yang

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

2 REPLIES 2
Super User II

Maybe check if Type has one value too?

______________

Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved.

I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query.

excelwithallison.com

Microsoft

Hi  @qubit813,

Here are the steps you can follow：

1. According to your description, the total may fail due to whether Type is multiple values.

Returns TRUE when the context for columnName has been filtered down to one distinct value only,Otherwise is FALSE.

As shown below:

When a value is selected, it is displayed as True.

When one or more values are selected, it is displayed as False.

2. For the problem of making the head office and the details the same, we can not only use HASONEVALUE, but also use HASONEFILTER function.

The difference between the two functions can be viewed at this link

https://docs.microsoft.com/en-us/dax/hasonefilter-function-dax

3.  In this regard, I created data to simulate the use of two functions HASONEVALUE and HASONEFILTER for you.

Data created:

Created measure:

``````Measure =
IF(SUM('Dimension Employee Schedule'[Amount])<300,0,SUM('Dimension Employee Schedule'[Amount]))

HASONEFILTER =
IF(HASONEFILTER('Dimension Employee Schedule'[Date]),
IF(SUM('Dimension Employee Schedule'[Amount])<300,0,SUM('Dimension Employee Schedule'[Amount])),
SUMX(FILTER('Dimension Employee Schedule',[Amount]>300),[Amount])
)

HASONEVALUE =
var _new=SUMMARIZE('Dimension Employee Schedule','Dimension Employee Schedule'[Date],"_value",[Measure])
return IF(HASONEVALUE('Dimension Employee Schedule'[Date]),[Measure],SUMX(_new,[_value]))``````

4. Result.

If this response does not meet your needs, can you provide a copy of sample data.

Best Regards,

Liu Yang

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

Announcements

#### Power Platform Community Conference

Check out the on demand sessions that are available now!

#### Microsoft Power Platform Communities

Check out the Winners!

#### Create an end-to-end data and analytics solution

Learn how Power BI works with the latest Azure data and analytics innovations at the digital event with Microsoft CEO Satya Nadella.

Top Solution Authors
Top Kudoed Authors