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
punksterz626
Helper II
Helper II

How to calculate SUM with IF statement and CONTAIN

Hello Team,

 

Hope everyone is doing well. I am hoping someone can assist me with writing a measure that satisfies these conditions. 

 

I have a table, see below, that has multiple columns, project number, name, and percentage value. 

I want to sum the total percentage for any given name; however, with one caveat. I have a list of names that I want to automatically add 40% on top of what the total would be.

 

For example, John (20,10,20) and Ana (40,20) are on this list. Normally their number would sum as 50 (Andy) and 60 (Ana), but since they're on this list their total would be 90 for Andy and 100 for Ana. Is this achievable?

 

Project Num  Name              Percentage   Result I want (sum of percentage)

111John2090
123Andy1030
214John1090
915Chris1020
852Jason3060
741Ana40100
159Steve2030
456John2090
789Andy2030
321Chris1020
147Jason3060
258Ana20100
369Steve1030
1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

You can multiply the additional 40% with a boolean test of whether the name is Ana or John.

 

Sum of Percentage =
CALCULATE ( SUM ( Table1[Percentage] ), ALLEXCEPT ( Table1, Table1[Name] ) )
    + 40 * ( SELECTEDVALUE ( Table1[Name] ) IN { "Ana", "John" } )

 

 

Edit: As @jgeddes suggests, you can replace a hardcoded list { "Ana", "John" } with a reference to another list like VALUES ( nameTable[Name] ) if you need a more dynamic approach.

AlexisOlson_0-1662067439192.png

View solution in original post

4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hi @punksterz626,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
AlexisOlson
Super User
Super User

You can multiply the additional 40% with a boolean test of whether the name is Ana or John.

 

Sum of Percentage =
CALCULATE ( SUM ( Table1[Percentage] ), ALLEXCEPT ( Table1, Table1[Name] ) )
    + 40 * ( SELECTEDVALUE ( Table1[Name] ) IN { "Ana", "John" } )

 

 

Edit: As @jgeddes suggests, you can replace a hardcoded list { "Ana", "John" } with a reference to another list like VALUES ( nameTable[Name] ) if you need a more dynamic approach.

AlexisOlson_0-1662067439192.png

jgeddes
Super User
Super User

If there are too many names to hard code into the measure and the names exist on another table you can use

Conditional Sum =
var _sum =
SUMX(
    FILTER(ALL('Table'),'Table'[Name] = SELECTEDVALUE('Table'[Name])),
    'Table'[Percentage]
)
var _nameOnList =
IF(
    NOT(ISBLANK(LOOKUPVALUE(nameTable[Name],nameTable[Name],SELECTEDVALUE('Table'[Name])))),
    TRUE(),
    FALSE()
)
Return
IF(
    _nameOnList,
    _sum + 40,
    _sum
)



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

Proud to be a Super User!





jgeddes
Super User
Super User

The measure

Conditional Sum =
var _sum =
SUMX(
    FILTER(ALL('Table'),'Table'[Name] = SELECTEDVALUE('Table'[Name])),
    'Table'[Percentage]
)
Return
IF(
    SELECTEDVALUE('Table'[Name]) = "John" || SELECTEDVALUE('Table'[Name]) = "Ana",
    _sum + 40,
    _sum
)
gets me the result
jgeddes_0-1662066026912.png

 




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

Proud to be a Super User!





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.