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
T_Francis
Frequent Visitor

Diferencia entre fechas en número de semanas

Hola

Estoy tratando de plantear un informe simple que muestra el número de semanas entre dos fechas, no he sido capaz de encontrar cómo hacerlo, ¿podría alguien por favor ayudar.

Sólo una tercera columna que muestra el número de semanas con 1 como mínimo es todo lo que necesito.

T_Francis_0-1595428357975.png

Gracias

9 REPLIES 9
FrankAT
Community Champion
Community Champion

Hola @T_Francis

puede hacerlo dentro de Power Query de la siguiente manera:

// Table
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dZBRCsAgDEPv4rfQtHVzO4t4/2usCs4q+BmeaRJLCZKIQQLmEIPiFzWWgIsgTcKYgSE6E8eECfdk8hJ4MPews+yZ+dTdVH9TV9/jfHsX9j0tPB0Y9Oxrxd6TL5+3b/uWDVvesl023/LXM7zWDw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"HCT START DATE" = _t, #"HCT PLANNED END DATE" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"HCT START DATE", type date}, {"HCT PLANNED END DATE", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "# of Weeks", each Number.RoundUp(Number.From([HCT PLANNED END DATE] - [HCT START DATE]) / 7,0)),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"# of Weeks", Int64.Type}})
in
    #"Changed Type1"

23-07-_2020_0-17-44.png

Saludos FrankAT

AntrikshSharma
Community Champion
Community Champion

( Fecha 1 - Fecha 2 ) / 7 ?

Gracias por responder, pero de esta manera envía un mensaje de error.

T_Francis_0-1595430697079.png

az38
Community Champion
Community Champion

@T_Francis

todavía parece una columna personalizada para la interfaz de Power Query.


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Use los botones de transformación de la cinta de opciones, vea cómo lo hice.

let
    Source = Excel.CurrentWorkbook(){[Name = "Table23"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(
        Source, 
        {{"Date", type date}, {"Other Date", type date}}
    ),
    #"Inserted Date Subtraction" = Table.AddColumn(
        #"Changed Type", 
        "Subtraction", 
        each Duration.Days([Other Date] - [Date]), 
        Int64.Type
    ),
    #"Divided Column" = Table.TransformColumns(
        #"Inserted Date Subtraction", 
        {{"Subtraction", each _ / 7, type number}}
    ),
    #"Rounded Up" = Table.TransformColumns(
        #"Divided Column", 
        {{"Subtraction", Number.RoundUp, Int64.Type}}
    )
in
    #"Rounded Up"

1.PNG

Lo que el error sería sería útil, que sólo dice que el error no es demasiado útil

Si usted está deseando que muestre 1 semana para 1-7 días, 2 semanas para 8-14 días, etc,entonces este es realmente un caso simple de encontrar la diferencia en días, dividiendo por 7, luego usando Number.RoundUp (si usa Power Query) o ROUNDUP (en DAX)

parry2k
Super User
Super User

@T_Francis puede agregar una nueva columna usando dax

Number of Weeks = MIN ( DATEDIFF ( Table[Start Date], Table[End Dat], WEEK ), 1 )

Me gustaría elogiossi mi solución ayudara.👉Si puedes pasar tiempo publicando la pregunta, también puedes hacer esfuerzos para dar a Kudos quien haya ayudado a resolver tu problema. ¡Es una muestra de agradecimiento!

Visítenos enhttps://perytus.com, su ventanilla única para proyectos/formación/consulta relacionadas con Power BI.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Gracias

La fórmula no parece estar funcionando

T_Francis_0-1595430236284.png

T_Francis_1-1595430259200.png

¿Estoy cometiendo un error en alguna parte?

Necesito usar el resultado en una hoja de cálculo, así que ¿hay una manera de hacerlo en la consulta de energía o tengo que crear una medida?

Sí, lo que escribió es código DAX y estás escribiendo código M.

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.