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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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