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
gianmarco
Helper IV
Helper IV

Sum values by description that contains a common part of a string

Dear Friends,

I have the following table:

DescriptionValue
Apple One3
Orange One8
Apple Two4
Orange Two10

 

I have to sum those values which contains "Two" in the description.

How can one achieve that without using a lot of CALCULATE formulas?

Thanks

 

2 ACCEPTED SOLUTIONS
selimovd
Super User
Super User

Hey @gianmarco ,

 

I think the best approach is without any CALCULATE at all 😉

Try that one:

Sum contains Two =
SUMX(
    myTable,
    IF(
        CONTAINSSTRING( myTable[Description], "two" ),
        myTable[Value]
    )
)

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

View solution in original post

CNENFRNL
Community Champion
Community Champion

Sum TWO = 
CALCULATE(
    SUM( 'Table'[Value] ),
    CONTAINSSTRING( 'Table'[Description], "TWO" )
)

Screenshot 2021-06-17 172254.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

4 REPLIES 4
CNENFRNL
Community Champion
Community Champion

Sum TWO = 
CALCULATE(
    SUM( 'Table'[Value] ),
    CONTAINSSTRING( 'Table'[Description], "TWO" )
)

Screenshot 2021-06-17 172254.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

selimovd
Super User
Super User

Hey @gianmarco ,

 

I think the best approach is without any CALCULATE at all 😉

Try that one:

Sum contains Two =
SUMX(
    myTable,
    IF(
        CONTAINSSTRING( myTable[Description], "two" ),
        myTable[Value]
    )
)

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

Dear @selimovd

thank you so much! Both of your formulas solve my issue! I'm gonna accept @CNENFRNL's solution as he replied me earlier. Anyway, again, thank you a lot!

Hey @gianmarco ,

 

you can also accept multiple posts as solution if they work for you 😉

But I'm happy you found a result for your problem.

 

Have a great weekend

Denis

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.