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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
nath2544
Frequent Visitor

Matrix Visual custom calculation

Hi,
from this picture is my sample matrix visual. I want to make a custom calculation for each Category. When put value in matrix table it will sum value of each item automatically. But what if I want a different calculation. Example, the total value of Category 2 is sum of all item in Category 2 + total of Category 3. And the total value of Category 2 must be the total value of Category 1 subtracted by the total value of Category 2.

Is there any solution or workaround? Any suggestion is appreciated.

nath2544_1-1733973689965.png


Expected result,

nath2544_2-1733974703692.png

 

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1733977428098.png

 

 

Jihwan_Kim_0-1733977403448.png

 

ISINSCOPE function (DAX) - DAX | Microsoft Learn

 

expected result measure: = 
VAR _valuetotal = [value total:]
VAR _subcategory2result =
    CALCULATE ( SUM ( data[Value] ), sub_category[category] = 2 )
        + CALCULATE ( SUM ( data[Value] ), sub_category[category] = 3 )
VAR _subcategory3result =
    CALCULATE ( SUM ( data[Value] ), sub_category[category] = 1 )
        - CALCULATE ( SUM ( data[Value] ), sub_category[category] = 2 )
RETURN
    SWITCH (
        TRUE (),
        ISINSCOPE ( sub_category[sub_category] ), _valuetotal,
        ISINSCOPE ( sub_category[category] )
            && MAX ( sub_category[category] ) = 2, _subcategory2result,
        ISINSCOPE ( sub_category[category] )
            && MAX ( sub_category[category] ) = 3, _subcategory3result
    )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

2 REPLIES 2
nath2544
Frequent Visitor

This solution works. But what if the same sub_category belongs to another category like sub_cat A it refers to category 2.
As far as I know, the relationship will be broken because the sub_category is a primary key here.

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1733977428098.png

 

 

Jihwan_Kim_0-1733977403448.png

 

ISINSCOPE function (DAX) - DAX | Microsoft Learn

 

expected result measure: = 
VAR _valuetotal = [value total:]
VAR _subcategory2result =
    CALCULATE ( SUM ( data[Value] ), sub_category[category] = 2 )
        + CALCULATE ( SUM ( data[Value] ), sub_category[category] = 3 )
VAR _subcategory3result =
    CALCULATE ( SUM ( data[Value] ), sub_category[category] = 1 )
        - CALCULATE ( SUM ( data[Value] ), sub_category[category] = 2 )
RETURN
    SWITCH (
        TRUE (),
        ISINSCOPE ( sub_category[sub_category] ), _valuetotal,
        ISINSCOPE ( sub_category[category] )
            && MAX ( sub_category[category] ) = 2, _subcategory2result,
        ISINSCOPE ( sub_category[category] )
            && MAX ( sub_category[category] ) = 3, _subcategory3result
    )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.