Counting responses in rows - multiple text strings needs to be ignored

Anything related to PowerPivot and DAX Formuale
ddw
Posts: 1
Joined: Thu Dec 10, 2020 3:21 pm

Counting responses in rows - multiple text strings needs to be ignored

Postby ddw » Thu Dec 10, 2020 3:23 pm

Hi Forum

I need to count rows with a measure where there are some "regular", and some "mixed" responses to a survey all stuck in one column. I need to count the columns where "other" responses where provided.

For simplicity, lets call the regular responses A, B and C.

All regular responses A's, B's and C's are always the same, so A might be = "yes", B = "no", C = "don't know", as an example.
And lets call all other responses X. X can be anything. Like - X = "this is a stupid survey" or X = "why are we doing this"

So the data might be as follows in my Survey_Column:
row 1 : A; B; C
row 2 : A; B
row 3 : X
row 4 : X; A; B

I've tried:

CALCULATE(
COUNTROWS('Table'),
SEARCH("A",'Table'[Survey_Column],1,-1)=-1,
SEARCH("B",'Table'[Survey_Column],1,-1)=-1,
SEARCH("C",'Table'[Survey_Column],1,-1)=-1
)

This returns a count of 1, since all the rows with A, B and C has been left out. But I need the count to be 2, since there are two rows where other responses were provided?

MattAllington
Posts: 1154
Joined: Sun May 04, 2014 4:01 pm
Location: Sydney, Australia

Re: Counting responses in rows - multiple text strings needs to be ignored

Postby MattAllington » Sun Dec 27, 2020 7:01 am

I suggest you split the responses into rows. You can do this in power query using the split columns by delimiter feature. Just make sure you select “to rows”. Then you table will have one row for each answer.
Matt Allington is Self Service BI Consultant, Trainer and Author of the Book "Supercharge Power BI".
Power BI Training

rwfigtree
Posts: 22
Joined: Tue Jan 05, 2021 8:49 pm
Location: Sydney, Australia

Re: Counting responses in rows - multiple text strings needs to be ignored

Postby rwfigtree » Tue Jan 05, 2021 9:46 pm

yes power query is the way to go.

[c1] is the column with your ";" delimited list.
add a custom column which splits the answers into a list, removes entries of A B c, then counts the remaining entries.

= Table.AddColumn(#"Changed Type", "Custom", each List.Count(List.RemoveItems( Text.Split([c1],";"),{"A","B","C"})))

returns number > 0 if answer list has any entries other than A B C

in dax you can then count rows with the custom column value > 0

eg calculate(countrows(table),filter(table,customcolumn>0))


Return to “PowerPivot/DAX”

Who is online

Users browsing this forum: No registered users and 5 guests