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
alicek
Helper II
Helper II

¿Utiliza Text.PadStart en el Editor de consultas de una columna personalizada para agregar 0 delante de un solo dígito?

Hola a todos,

Tengo una columna con los ID de sitio que están llenos con: 1, 2, 3, 4, 10, 11, 12, A, AB y B.

Sólo los sitios con números son sitios de "Construcción" (los ID de sitio alfabéticos son un tipo diferente de sitio).
Estoy creando una columna personalizada que volverá a escribir estos IDs para que coincidan con otra tabla en la que necesito combinar con esa columna.

A continuación, la columna se rellenaría con: Sitio 01, Sitio 02, Sitio 03, Sitio 04, Sitio 10, Sitio 11, Sitio 12, Sitio A, Sitio AB y Sitio B.


Escribí este texto en el editor de columnas personalizadas, pero no está agregando un 0 delante de los números de un solo dígito:

si [Tipo de sitio] - "Construcción"
a continuación, Text.Combine('"Sitio ", Texto.PadStart(Text.From(['"Sitio '"], 'en-US'), 2, "0")')
else Text.Combine('Sitio ', 'Text.PadStart(Text.From(['"Sitio''], 'en-US'), 1)')

¿Alguien puede señalarme a donde me he equivocado? ¡¡Gracias!!

3 REPLIES 3
ChrisMendoza
Resident Rockstar
Resident Rockstar

@alicek - Intenté como:

= Table.AddColumn(#"Added Custom", "Custom1", each Text.Combine({"Site ", if Value.Is(Value.FromText([siteID]), type number) then Text.PadStart([siteID],2,"0") else [siteID]}))

image.png

Https://stackoverflow.com/a/39736101 usados →






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



HotChilli
Super User
Super User

A mí me parece bien.

Depurarlo cortándolo a la derecha. Intente agregar una columna con solo

Text.PadStart(Text.From([-"Sitio"], "en-US"), 2, "0")

Si eso funciona, agregue el Text.Combine, a continuación, el 'if' instrucción

PhilipTreacy
Super User
Super User

Hola @alicek

Este código funcionará

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs7PKy4pKk0uyczPU9JRMlSK1YlW8k9Ly0xOhXPR1BihqjHCpsYYVY0xNjUmqGpMsKkxNEBzkAE2VY6oihydiFCEVQ1QMBYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Site Type" = _t, #"Site ID" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Site Type", type text}, {"Site ID", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Site Type] = "Construction" and List.ContainsAny(Text.ToList([Site ID]), { "0" .. "9" }) then Text.PadStart([Site ID],2,"0") else [Site ID] )
in
    #"Added Custom"

saludos

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


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.