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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Anonymous
Not applicable

Matrix column based on other matrix columns

Hi!

 

I am moving reports from excel to Power BI, and have encountered this problem.

 

This is how my data look like:

gusjohjoco_0-1641827768397.png

 

I arrange a matrix as following:

gusjohjoco_2-1641827811682.png

 

Now I want to add one more column which is based on the other two columns, like this:

gusjohjoco_3-1641827854334.png

 

If I create a measure of income 2020 - income 2019, the calculations are correct but it is not possible to add it as a column.

Anyone have an idea of how to do it? In excel, I would create a pivot table, and then create a new nice table which refers to the pivot table and simply add a column which subtracts the two columns. I have tried creating an additional matrix with measures on the rows, but it doesn't seems to be the most efficient way + it doesn't look so nice.

 

gusjohjoco_4-1641828583684.png

 

 

5 REPLIES 5
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

Has @PaulDBrown 's solution solved your problem? If yes, please kindly accept it as the solution to help the other members find it more quickly.

Best Regards,
Community Support Team _ kalyj

parry2k
Super User
Super User

@Anonymous here you go, you have a solution. As I mentioned earlier, not as straightforward but a workaround. You have to be very specific to your requirements to make it work since the measure is tightly knitted, if you drift from your requirement, you have to come back and revisit your measures.

 

One way to make it simple is to use calculation groups which will make the repeated calculation easier. Cheers!!

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@Anonymous unfortunately there is no straightforward solution to this, it will show diff measures as row since you have turned on show on rows (looks like)


There are workaround available, you can do a google search and will find some solution.

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

@parry2k  Thank you for your reply.

 

So far, I have not found a solution by googling. And I have googled on this for many hours.

Please, if you can find solution, let me know.

Here is one way. 

1) create a new table as the layout for the matrix columns. In my example, I've used the following code  in the new table option under modeling:

Matrix columns =
DISTINCT ( UNION ( VALUES ( 'Table'[Year] ), { "Diff" } ) )

I've added an index column for sorting purposes

index.jpg

 2) Create a relationship one-to-many between the 2 tables via the "Year" fields

model.jpg

 

3) Using simple base measures for the sum of income and cost, create the following tto use in the visual:

Icome (visual) =
VAR MXYear =
    CALCULATE (
        MAX ( 'Matrix columns'[Index] ),
        ALLSELECTED ( 'Matrix columns'[Year] )
    )
VAR MNYear =
    CALCULATE (
        MIN ( 'Matrix columns'[Index] ),
        ALLSELECTED ( 'Matrix columns'[Year] )
    )
VAR MXValue =
    CALCULATE (
        [Sum Icome],
        FILTER ( ALL ( 'Matrix columns' ), 'Matrix columns'[Index] = MXYear )
    )
VAR MNValue =
    CALCULATE (
        [Sum Icome],
        FILTER ( ALL ( 'Matrix columns' ), 'Matrix columns'[Index] = MNYear )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Matrix columns'[Year] ) = "Diff",
        MXValue - MNValue,
        [Sum Icome]
    )
Cost (visual) =
VAR MXYear =
    CALCULATE (
        MAX ( 'Matrix columns'[Index] ),
        ALLSELECTED ( 'Matrix columns'[Year] )
    )
VAR MNYear =
    CALCULATE (
        MIN ( 'Matrix columns'[Index] ),
        ALLSELECTED ( 'Matrix columns'[Year] )
    )
VAR MXValue =
    CALCULATE (
        [Sum Cost],
        FILTER ( ALL ( 'Matrix columns' ), 'Matrix columns'[Index] = MXYear )
    )
VAR MNValue =
    CALCULATE (
        [Sum Cost],
        FILTER ( ALL ( 'Matrix columns' ), 'Matrix columns'[Index] = MNYear )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Matrix columns'[Year] ) = "Diff",
        MXValue - MNValue,
        [Sum Cost]
    )

4) create the matrix using the measures on rows and the Year field from the Matrix layout table to get:

result.jpg

 

I've attached the sample PBIX file for you





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

Top Kudoed Authors