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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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]))


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

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]))


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

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])


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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