cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Post Patron
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
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.

v-yangliu-msft_0-1602491622573.jpeg

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

v-yangliu-msft_1-1602491622576.jpeg

 

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:

v-yangliu-msft_2-1602491622577.png

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.

v-yangliu-msft_3-1602491622579.jpeg

 

You can downloaded PBIX file from here.

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.

View solution in original post

2 REPLIES 2
Super User II
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. 


If you found this post helpful, please give Kudos.


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


excelwithallison.com

Microsoft
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.

v-yangliu-msft_0-1602491622573.jpeg

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

v-yangliu-msft_1-1602491622576.jpeg

 

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:

v-yangliu-msft_2-1602491622577.png

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.

v-yangliu-msft_3-1602491622579.jpeg

 

You can downloaded PBIX file from here.

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.

View solution in original post

Helpful resources

Announcements
November Update

Check it Out!

Click here to read more about the November 2020 Updates!

Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

secondImage

Power Platform October Community Highlights

Check out the top community contributors across all of the communities

secondImage

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