cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
qubit813
Post Partisan
Post Partisan

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
v-yangliu-msft
Community Support
Community Support

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
v-yangliu-msft
Community Support
Community Support

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.

AllisonKennedy
Super User
Super User

Maybe check if Type has one value too?


Please @mention me in your reply if you want a response.

Check out my Olympics report with live stats - KUDOS much appreciated

Has this post solved your problem? Please Accept as 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 C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors