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
Anonymous
Not applicable

Creating measure to calculate sum from a column based on other column

Hello,

I am trying to calculate sum of achieved to plot against milestones of an asset in a matrix table. 

Complication here is for milestone 1 i have one milestone entry so it picks 10, for milestone two i want to pick 15 but i end up getting 30 while for milestone 3 i am looking to get 18. its a bit tricky and i am stuck. any help is appreciateed thanks.

assetmilestone activityachieved
Amilestone1milestone 1 activity10
Amilestone2 Milestone 2 activity a15
Amilestone2 Milestone 2 activity b15
Amilestone3Milestone 3 activity a2
Amilestone3 Milestone 3 activity b5
Amilestone 3 Milestone 3 activity c11

 

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

You can use IF or SWITCH function to judge the condition fot the calculation.

Try measure like this:

Measure =
SWITCH (
    TRUE (),
    MAX ( 'Table'[milestone] ) = "Construct", CALCULATE (
        SUM ( 'Table'[achieved] ),
        ALLEXCEPT ( 'Table', 'Table'[asset ], 'Table'[milestone] )
    ),
    CALCULATE (
        FIRSTNONBLANK ( 'Table'[achieved], 1 ),
        ALLEXCEPT ( 'Table', 'Table'[milestone] )
    )
)

test_Creating measure to calculate sum from a column based on  other column.PNG

 

Best Regards,
Liang
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

5 REPLIES 5
amitchandak
Super User
Super User

@Anonymous , Try a new measure like

measure =
sumx(summarize(Table,Table[asset],Table[milestone],Table[achieved]),[achieved])

admin_muntap
New Member

Sounds like the matrix is doing its work right based on data.

If you are looking for milestone2 to return 15 (not 30) and milestone3 to return 30 (all the values in 3 rows), what is your selectio criteria?

Which rows to keep and which ones to skip?

@Anonymous provide the business logic why you want to sum up for milestone 3 and not for 2. Read this post to get your answer quickly.

https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



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

Hello, thankyou for the reply. The bussiness logic is  that i have milestones like permissions which are done for entirety of  the asset while some like consruction which are done in parts. Need to calculate sum of achieved till target date. Overall achievement possible is 15 but due to multiple permission entry in column it goes to being 30 while in case of construction it needs to be summed to get 15. While there are also activity like engeneeerig which are one entry per asset location and works fine in a simple  measure.  

asset milestoneactivityachievedTarget date
gas stationEngineeringEngineering complete1510/5/2020
gas stationPermission appliedPermission for construction1515/5/2020
gas stationPermission appliedPermission for Land purchase1515/5/2020
gas stationPermission receivedPermission for land received155/6/2020
gas stationPermission receivedPermission for construction received155/6/2020
gas stationConstructConstruction of x complete1130/5/2020
gas stationConstructConstruction of y complete410/6/2020

 

Thankyou for your time

-A newbie Pbi developer

Hi @Anonymous ,

 

You can use IF or SWITCH function to judge the condition fot the calculation.

Try measure like this:

Measure =
SWITCH (
    TRUE (),
    MAX ( 'Table'[milestone] ) = "Construct", CALCULATE (
        SUM ( 'Table'[achieved] ),
        ALLEXCEPT ( 'Table', 'Table'[asset ], 'Table'[milestone] )
    ),
    CALCULATE (
        FIRSTNONBLANK ( 'Table'[achieved], 1 ),
        ALLEXCEPT ( 'Table', 'Table'[milestone] )
    )
)

test_Creating measure to calculate sum from a column based on  other column.PNG

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.