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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

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.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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