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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
StefanM
Helper II
Helper II

Ayuda - Combinar fechas con la tabla de fechas

¡Hola!

Estoy teniendo algunos problemas con lo que estoy seguro es un problema muy fácil de resolver, pero creo que he estado trabajando en ello durante tanto tiempo ahora que estoy girando en círculos :C

Esta es la situación:

  • Tengo una tabla de fechas en PBI que cubre todos los días entre 2019 y 2022.
  • He importado un XLSX que enumera a las personas por su rango.
  • Este XLSX detalla cuando comenzaron ese rango junto con la lista de los rangos anteriores y cuando se iniciaron también.
  • Estoy tratando de generar una mesa con personas en un eje y fechas en el otro.
  • Con los datos de la tabla siendo su rango actual en ese momento.

He aquí una idea visual de lo que estoy hablando: https://i.imgur.com/7cf17St.png

Como pueden ver, la mesa de la izquierda no es vertical, que es lo que me está desentrando. Si fueron cuatro columnas: Quién, Rango, Actual/Anterior, Fecha de inicio - entonces creo que puedo conseguir que funcione. Pero eso no es lo que se necesita en esta situación y oh hombre, ¿ahora estoy perdido en el código!

¿Puede alguien encontrar una manera de crear esta tabla sin tener que remodelar los datos antes de importarlos?

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Hola @StefanM ,

esta es una versión que se puede hacer a través de la interfaz de usuario solamente.

Pegue el código en el editor avanzado y siga estos pasos:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcixLLapU0lFyzCnISATSBob6hgb6RgZGBkCOU2oJWMwILharE60UlJmTWolVVkcJhGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Who = _t, #"Current Rank" = _t, Since = _t, Previous1 = _t, Since1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Who", type text}, {"Current Rank", type text}, {"Since", type date}, {"Previous1", type text}, {"Since1", type date}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Who"}, "Attribute", "Value"),
    #"Added Index" = Table.AddIndexColumn(#"Unpivoted Other Columns", "Index", 0, 1, Int64.Type),
    #"Inserted Integer-Division" = Table.AddColumn(#"Added Index", "Integer-Division", each Number.IntegerDivide([Index], 2), Int64.Type),
    #"Integer-Divided Column" = Table.TransformColumns(#"Inserted Integer-Division", {{"Index", each Number.Mod(_, 2), Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Integer-Divided Column",{"Attribute"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Index", type text}}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Changed Type1", {{"Index", type text}}, "en-GB"), List.Distinct(Table.TransformColumnTypes(#"Changed Type1", {{"Index", type text}}, "en-GB")[Index]), "Index", "Value"),
    #"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"Integer-Division"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Removed Columns1",{{"1", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type2", each ([1] <> null)),
    #"Pivoted Column1" = Table.Pivot(Table.TransformColumnTypes(#"Filtered Rows", {{"1", type text}}, "en-GB"), List.Distinct(Table.TransformColumnTypes(#"Filtered Rows", {{"1", type text}}, "en-GB")[#"1"]), "1", "0")
in
    #"Pivoted Column1"

La próxima vez, proporcione datos de muestra que se puedan copiar fácilmente:

https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

2 REPLIES 2
ImkeF
Community Champion
Community Champion

Hola @StefanM ,

esta es una versión que se puede hacer a través de la interfaz de usuario solamente.

Pegue el código en el editor avanzado y siga estos pasos:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcixLLapU0lFyzCnISATSBob6hgb6RgZGBkCOU2oJWMwILharE60UlJmTWolVVkcJhGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Who = _t, #"Current Rank" = _t, Since = _t, Previous1 = _t, Since1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Who", type text}, {"Current Rank", type text}, {"Since", type date}, {"Previous1", type text}, {"Since1", type date}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Who"}, "Attribute", "Value"),
    #"Added Index" = Table.AddIndexColumn(#"Unpivoted Other Columns", "Index", 0, 1, Int64.Type),
    #"Inserted Integer-Division" = Table.AddColumn(#"Added Index", "Integer-Division", each Number.IntegerDivide([Index], 2), Int64.Type),
    #"Integer-Divided Column" = Table.TransformColumns(#"Inserted Integer-Division", {{"Index", each Number.Mod(_, 2), Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Integer-Divided Column",{"Attribute"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Index", type text}}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Changed Type1", {{"Index", type text}}, "en-GB"), List.Distinct(Table.TransformColumnTypes(#"Changed Type1", {{"Index", type text}}, "en-GB")[Index]), "Index", "Value"),
    #"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"Integer-Division"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Removed Columns1",{{"1", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type2", each ([1] <> null)),
    #"Pivoted Column1" = Table.Pivot(Table.TransformColumnTypes(#"Filtered Rows", {{"1", type text}}, "en-GB"), List.Distinct(Table.TransformColumnTypes(#"Filtered Rows", {{"1", type text}}, "en-GB")[#"1"]), "1", "0")
in
    #"Pivoted Column1"

La próxima vez, proporcione datos de muestra que se puedan copiar fácilmente:

https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

amitchandak
Super User
Super User

@ImkeF, ¿puede ayudar en este

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors