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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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!:
Mastering Power BI 2nd Edition

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!:
Mastering Power BI 2nd Edition

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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