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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
gmasta1129
Helper III
Helper III

Formula - Sum values in a column based on another column

Hello,

 

I created a matrix (portfolio code is the first column) and trying to figure out a formula to sum up the profit and loss column by Master portfolio code.  the columns are as follows...

 

gmasta1129_1-1645574608168.png

 

 

 

For ex: Port Code 71111 and 71112  roll up into the same Master Port Code of 71111.  I need the profit and loss for 71111 and 71112 summed together (100,000+200,000) = 300,000

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @gmasta1129 ,

You can create a measure as below to get the [Net Profit and Loss], and the value will be changed dynamically base on the slicer date selections.... Please find the details in the attachment.

Net Profit and Loss = 
CALCULATE (
    SUM ( 'Table'[Profit and Loss] ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[Master Portfolio Code]
            = SELECTEDVALUE ( 'Table'[Master Portfolio Code] )
    )
)

yingyinr_0-1645755322709.png

Best Regards

View solution in original post

gmasta1129
Helper III
Helper III

Worked perfectly!! Thank you so much for your help! @Anonymous 

View solution in original post

5 REPLIES 5
gmasta1129
Helper III
Helper III

Worked perfectly!! Thank you so much for your help! @Anonymous 

gmasta1129
Helper III
Helper III

Hello,

 

Thank you for the responses. I tried both formula's and they did not work.  I forgot to mentioned that i have a column labeled Run Date which is being used a a slicer.  Would i need to add this to the formula? I need the net profit and loss by date. 

 

gmasta1129_1-1645581112284.png

 

 

See result below using @YukiK formula

 

 

gmasta1129_0-1645581062265.png

 

 

 

Anonymous
Not applicable

Hi @gmasta1129 ,

You can create a measure as below to get the [Net Profit and Loss], and the value will be changed dynamically base on the slicer date selections.... Please find the details in the attachment.

Net Profit and Loss = 
CALCULATE (
    SUM ( 'Table'[Profit and Loss] ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[Master Portfolio Code]
            = SELECTEDVALUE ( 'Table'[Master Portfolio Code] )
    )
)

yingyinr_0-1645755322709.png

Best Regards

moizsherwani
Continued Contributor
Continued Contributor

NetProfitAndLossExample.PNGHere is the code

 

NetProfitAndLoss = 
VAR SelectedMasterPortfolioCode =
    SELECTEDVALUE ( Sampledata[Master PortfolioCode] )
RETURN
    CALCULATE (
        SUM ( Sampledata[Profit and Loss] ),
        FILTER (
            ALL ( Sampledata ),
            Sampledata[Master PortfolioCode] = SelectedMasterPortfolioCode
        )
    )

 

 

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.
YukiK
Impactful Individual
Impactful Individual

I would create a measure like this:

Sum of Profit and Loss Per Master Code = 
    CALCULATE( 
        SUM (MyTable[profit and loss]),
        ALLEXCEPT( MyTable, MyTable[master code] )
    )

YukiK_0-1645577353098.png
Hope this helps!

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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