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

Count the number of characters in a string without duplication

I have a table which stores the LPResult for a number of LPHeadings for a student. The data also comes in with a comment on the student. Due to the way the table was created, the comment for each student is duplicated on each of the LPHeading row.

StudentLPHeadingLPResultCommentNumber of Characters
John A5Test4
John B5Test4
John C4Test4
SueA4Good Student12
SueB4Good Student12
SueC3Good Student12
SueD4Good Student12
SueE3Good Student12
PeterA5Works hard10
PeterB4Works hard10
PeterC5Works hard10
PeterD4Works hard10
SamA5 0
SamB4 0

 

Basically I want a simple count of the number of characters in the comment for each student. Ultimately, I want to check how many characters the comment is, with no comment returning 0. Above I have an example of a calculated column which counts the number of characters. Note due to the comment being duplicated, the count of characters is the same for each of the students' rows. How can I create a calculated column like this? Is a calculated column the best? Maybe a measure would be better? Could someone also tell me if this is better done using a measure where I can just have one row for each student with a measure which gives me a count of the number of  characters in their comment. Not sure how to do this due to the duplication of the comment over the rows for each student. Any help would be much appreciated. 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

As a column it is simply:

 

Column = LEN([Comment])

As a measure:

 

Measure 5 = LEN(MAX([Comment]))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi everyone,

 

When I add the data, while it is normal on the SQL side, I encounter the character problem in BI Data and Report as below. How can we solve this situation?

 

karakter_srn.PNG

 
Greg_Deckler
Super User
Super User

As a column it is simply:

 

Column = LEN([Comment])

As a measure:

 

Measure 5 = LEN(MAX([Comment]))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Clearly I overthought things a little bit and this was a pretty simple solution. Thanks for the help.

Expression.Error: The name 'LEN' wasn't recognized. Make sure it's spelled correctly.

@tangutoori Make sure you are adding"New Column" in Data Pane but not in "Power Query Editor

 

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




yes... i noted it. Am a new user .Dont mind asking simple things. can u explain what is the difference between addig a colum in query and data pane ?

HI THANKS FOR UR REPLY.

 

I HAVE A DOUBT.. CAN'T WE DO SAM THING IN A NEW COLUMN ?

The original formula I supplied was a DAX calculated column. If you want to do this in the Query Editor, then the formula for the column would be:

 

=Text.Length([Comment])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.