cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Bigglerum
Frequent Visitor

SUMX - Problem with return value from count operation

Hi

 

I have a Column with Chemical element symbols separated by ";" in each cell, eg [ H;O;Pb;Ti]

 

There are between 1 - 16 symbols in each cell from a list of 78 valid elements in another table. 

I want to create a count of these in a new column. Where the values are validated against the list of 78 elements and then counted in the column.

I have written the expression 

SUMX(
VALUES('104 Periodic Table Filter'[Element]),
CALCULATE(COUNT('201 Mineral Information'[Elements]))

This all works fine - but where the the count of elements exceeds 11 - it stays at 11.

The data is fine and I have changed the reference elements to another source - it is the same.

Maybe there is a simpler way to count without validation?


1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

Here's how I would count with validation using PATHCONTAINS:

ValidatedCount =
VAR CurrPath = SUBSTITUTE ( MineralInfo[ElementList], ";", "|" )
RETURN
    COUNTROWS (
        FILTER (
			PeriodicTable,
			PATHCONTAINS ( CurrPath, PeriodicTable[Element] )
		)
    )

 

View solution in original post

4 REPLIES 4
AlexisOlson
Super User
Super User

Here's how I would count with validation using PATHCONTAINS:

ValidatedCount =
VAR CurrPath = SUBSTITUTE ( MineralInfo[ElementList], ";", "|" )
RETURN
    COUNTROWS (
        FILTER (
			PeriodicTable,
			PATHCONTAINS ( CurrPath, PeriodicTable[Element] )
		)
    )

 

View solution in original post

Thanks also - this solution works perfectly and also makes a better solution, and I can re-use the logic in other conversions - Brilliant!!!

Bigglerum

Bigglerum
Frequent Visitor

Hi thanks for you fast reply

the first solution is the same as my original query and the second doesn't seem to fire.

 

If this helps anyone - I went for a less elegant solution but it works

=LEN(TRIM(Cell))-LEN(SUBSTITUTE(TRIM(Cell),";",""))+1

ie it works out on the ";" separator and adds 1 to the total






 

amitchandak
Super User
Super User

@Bigglerum , if these tables are connected correctly then one of these two should work

 

SUMX(
VALUES('104 Periodic Table Filter'[Element]),
CALCULATE(COUNT('201 Mineral Information'[Elements])) )

 

SUMX(
Summarize('104 Periodic Table Filter','104 Periodic Table Filter'[Element], "_1",
CALCULATE(COUNT('201 Mineral Information'[Elements])) ), [_1])

 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin
Want To Learn Power BI
Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Power BI December 2021 Update_carousel 768x460.jpg

Check it Out!

Click here to read more about the December 2021 Updates!

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Jan 2022 Dev Camp 768x460 copy.png

Power BI Dev Camp- January 27th, 2022

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors