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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
RandayOr
Frequent Visitor

Summing values differently in same column based on name

Hi All, 

 

I'm currently having an issue with the below formula, it is working as expected with the exception of when I try to have it use a different formula for "Earnings". I put an if statement in to indicate if the name is not equal to Earnings to perform the formula one way but if it is equal to earnings to instead add 2 other measurements. I confirmed the formula works perfectly for everything that does not have the name "Earnings" and that the measurements by themselves produce the desired results, but for some reason when the formula displays Earnings it does not add the 2 measures but instead operates as if it's not registering the name is Earnings. Any help would be appreciated. 

 

if(SELECTEDVALUE(Account[Name])<>"Earnings",
    calculate(
        sum(RawData[Amount]),
        CONTAINSSTRINGEXACT(RawData[Level_8_Consol],"+"),
            USERELATIONSHIP(RawData[Level_8],Account[Name])
        )
    -calculate(
        sum(RawData[Amount]),
        CONTAINSSTRINGEXACT(RawData[Level_8_Consol],"-"),
            USERELATIONSHIP(RawData[Level_8],Account[Name])
            ),Measure_Table[Measure1]+Measure_Table[Measure2]      
)
1 ACCEPTED SOLUTION

Sorry for any confusion, when I wrote out the example instead of putting "FCC_Retained Earnings Current" I shortened it to Earnings, the formula itself actually shows 

IF( Account <> "FCC_Retained Earnings Current", Plus - Minus, [Measure1] + [Measure2] ). 

 

I ended up switching the Cross Filter Direction from the Accounts table to the RawData table to Single cross filter direction and it was able to start seeing the FCC_Retained Earnings Current but only if there was a static value instead of measurement in the if statement. Since this issue is different than what the post previously was I'll mark this one as solved and start a new thread/question. 

View solution in original post

4 REPLIES 4
hnguy71
Super User
Super User

Hi @RandayOr ,

 

Seems like your measure is more-or-less correct. I've just rebuilt it to have better readability:

VAR Account = SELECTEDVALUE(Account[Name])
VAR Plus = 
    CALCULATE( 
        SUM(RawData[Amount]), 
        CONTAINSSTRINGEXACT(RawData[Level_8_Consol],"+"), 
        USERELATIONSHIP(RawData[Level_8],Account[Name]) 
    )

VAR Minus =     
    CALCULATE( 
        SUM(RawData[Amount]), 
        CONTAINSSTRINGEXACT(RawData[Level_8_Consol],"-"), 
        USERELATIONSHIP(RawData[Level_8],Account[Name]) 
    )

RETURN

IF( Account <> "EARNING", Plus - Minus, [Measure1] + [Measure2] )


We'll need to see what's the value output from [Measure1] and [Measure2]. Can you share a screnshot, sample data, or sample file?



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Went ahead and reformatted the way you suggested to make sure nothing was missed but received the same results. Here's a screenshot of the result I'm getting (currently filtering for just the 1 name). In the example I changed the name to Earnings to make it appear more simple but the name showing in the screenshot is what Earnings is actually displayed as. Output below shows Measure 1 and 2 correctly but Earnings is still off (results are those of Plus - Minus) 

 

RandayOr_0-1666705923765.png

 

Hi @RandayOr ,

 

So your "Account Name" is a full string that should look to see if "EARNING" is exact within the string and this is likely why it's never going to work.

 

Try this instead:

 

VAR Account = MAX(Account[Name])
VAR isEarning = SEARCH("EARNING", Account, 1, 0) > 0
VAR Plus = 
    CALCULATE( 
        SUM(RawData[Amount]), 
        CONTAINSSTRINGEXACT(RawData[Level_8_Consol],"+"), 
        USERELATIONSHIP(RawData[Level_8],Account[Name]) 
    )

VAR Minus =     
    CALCULATE( 
        SUM(RawData[Amount]), 
        CONTAINSSTRINGEXACT(RawData[Level_8_Consol],"-"), 
        USERELATIONSHIP(RawData[Level_8],Account[Name]) 
    )

RETURN

IF( NOT(isEarning), Plus - Minus, [Measure1] + [Measure2] )

 

 



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Sorry for any confusion, when I wrote out the example instead of putting "FCC_Retained Earnings Current" I shortened it to Earnings, the formula itself actually shows 

IF( Account <> "FCC_Retained Earnings Current", Plus - Minus, [Measure1] + [Measure2] ). 

 

I ended up switching the Cross Filter Direction from the Accounts table to the RawData table to Single cross filter direction and it was able to start seeing the FCC_Retained Earnings Current but only if there was a static value instead of measurement in the if statement. Since this issue is different than what the post previously was I'll mark this one as solved and start a new thread/question. 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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