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 September 15. Request your voucher.

Reply
ANC
Regular Visitor

I need help calculating totals based on another columns value

Hi everyone,

 

Hoping someone here can help me finish off the start I've made on this calculation.

 

#TEST =
var _AD = CALCULATE(
    SUM('Table'[Transaction_Type_Flag]),
    'Table'[Transaction_Type] = "AD",
    FILTER('Table' ,
        SELECTEDVALUE('Table'[ID]) = 'Table'[ID]))

return
CALCULATE(
  SUMX(
  SUMMARIZECOLUMNS(
    'Table'[ID],
    'Table'[Transaction_Value])
    ,
    IF(_AD <> 0 , SUM('Table'[Transaction_Value]) , 0)),'Table'[Transaction_Type] = "TR")
 
ANC_1-1683904536318.png

 

 

ANC_0-1683904463678.png

 

 

The outcome I am hoping for is for the total in the table visual to sum the transaction value for all IDs where the sum of transaction_type_flag is greater than 0. In this example it should show 125, the measure appears to be working at a row level but not at a total level.

 

The concept is that if an ID has been part of "AD" even once within a filtered date range, then I would like to see the sum of transaction_value, but if it has not been included in "AD" during that time period then it to return blank. The total needs to act as if it would in Excel, where it will sum only the values visible in the table visual.

I have tried other version of this sum that again I can get to work at a row level, but the total then takes a sum of all transaction_value where transaction_type = "TR", rather than a sum of all transaction_value where sum transaction_type_flag > 0.

 

This has to be done in a measure rather than a table/by filtering as there are other fields in the table that I need to display.

 

Thanks in advance for any help!

1 ACCEPTED SOLUTION
Wilson_
Super User
Super User

Hi ANC,

 

Try the below:

#TEST = 
-- returns all IDs with flag values other than 0
VAR Filtered =
SELECTCOLUMNS (
    FILTER (
        'Table',
        'Table'[Transaction Type Flag] > 0
    ),
    "ID", 'Table'[ID]
)
-- sums transaction value for all IDs that have at least one flag value other than 0
VAR Result =
CALCULATE (
    SUM ( 'Table'[Transaction Value] ),
    'Table'[ID] IN Filtered
)

RETURN Result

 

I took the same general approach as you (ie: a var to isolate the IDs, then returning calculation based on those IDs).

 

This was my resulting visual:

Wilson__0-1684093145403.png

(Also, thank you for sharing your raw data. That helped tremendously. For future reference, please share it as a table instead of a screenshot. That way, it'll be easier for people helping to re-create your dataset. :D)


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

3 REPLIES 3
Wilson_
Super User
Super User

Hi ANC,

 

Try the below:

#TEST = 
-- returns all IDs with flag values other than 0
VAR Filtered =
SELECTCOLUMNS (
    FILTER (
        'Table',
        'Table'[Transaction Type Flag] > 0
    ),
    "ID", 'Table'[ID]
)
-- sums transaction value for all IDs that have at least one flag value other than 0
VAR Result =
CALCULATE (
    SUM ( 'Table'[Transaction Value] ),
    'Table'[ID] IN Filtered
)

RETURN Result

 

I took the same general approach as you (ie: a var to isolate the IDs, then returning calculation based on those IDs).

 

This was my resulting visual:

Wilson__0-1684093145403.png

(Also, thank you for sharing your raw data. That helped tremendously. For future reference, please share it as a table instead of a screenshot. That way, it'll be easier for people helping to re-create your dataset. :D)


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





ANC
Regular Visitor

Thank you Wilson_!

This has worked perfectly! I knew I was somewhere on the right tracks, I was just missing the structure, so thank you!

And thanks for the tip on posting tables, this is my first time using this forum and couldn't quite work out the best way to do things but I've spotted the insert table icon now, I will be sure to use this next time!

Thanks once again!

You're welcome. 😄

 

And no worries, just an FYI to help you remove friction for anybody that sees your future posts.




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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