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
Ion_Ander
Helper I
Helper I

Repeat a text N times based on value of a column

I need to create a column in Power Query where a text( is an unichar code) appears repeated n times (n is a number that will be in a column named the STARS), this number goes from 0 to 5. I try with Text.Repeat(CharacterFromNumber(), 5), when i hardcode the number of repetition works fine, my problem is that i dont know how to say to put the value of the column STARS.

 

Basically what i need is to translate this DAX formula to M:

UNICODE  STARS=
REPT(UNICHAR(9733), AVERAGE(CLIENTS[STARS]))
&
REPT(UNICHAR(9734), 5-AVERAGE(CLIENTS[STARS]))

 

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

Finally found the solution, the problem was that List.Average expect a List so need to put the column name into {} to transform the column in a List

 

The formula:

 

Text.Repeat(Character.FromNumber(9733), List.Average({[ESTRELLAS]})) & Text.Repeat(Character.FromNumber(9734), 5-List.Average({[ESTRELLAS]}))

 

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

Finally found the solution, the problem was that List.Average expect a List so need to put the column name into {} to transform the column in a List

 

The formula:

 

Text.Repeat(Character.FromNumber(9733), List.Average({[ESTRELLAS]})) & Text.Repeat(Character.FromNumber(9734), 5-List.Average({[ESTRELLAS]}))

 

Greg_Deckler
Super User
Super User

@Ion_Ander - You want Text.Repeat


@ 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...

Yes, i know, but how i put in the second argument(number of repetitions) the value of the STARS column?

@Ion_Ander Whoops, should have read closer. You will have to refer to your table step and use List.Average(Table.Column( ) )


@ 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...

I get an error that says something like: cant convert Table type value to Text type

 

Text.Repeat(Character.FromNumber(9734), List.Average(Table.Column(dbo_CLIENTS, STARS)))

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.