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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

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

Community Support Team _ Rena
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

gmasta1129
Helper III
Helper III

Worked perfectly!! Thank you so much for your help! @v-yiruan-msft 

View solution in original post

5 REPLIES 5
gmasta1129
Helper III
Helper III

Worked perfectly!! Thank you so much for your help! @v-yiruan-msft 

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

 

 

 

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

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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