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

transformación de los datos de gantt char al programador

Hola

Tengo datos de resertvación de coche como en la primera tabla, es habitual como la opción gantt char.

pero quiero convertir a datos como en la segunda tabla. significa que quiero añadir para cada período de día valor 1 a cada reserva.

Tengo que hacer para hacer un programador visual (línea de tiempo) con tabla de matriz, donde sólo el color de fondo del valor 1 y obtener visual.

¿Alguien tiene idea de cómo hacer tal transformación?

Annotation 2020-05-05 224035.png

1 ACCEPTED SOLUTION

Hola @froxas ,

Claro, podemos crear una tabla calculada para satisfacer sus necesidades:

NewTable =
ADDCOLUMNS (
    CROSSJOIN (
        DISTINCT (
            SELECTCOLUMNS ( 'Table', "CarNumber", [Car number], "Project", [Project] )
        ),
        CALENDAR ( MIN ( 'Table'[From] ), MAX ( 'Table'[Till] ) )
    ),
    "Value",
    VAR d = [Date]
    VAR cn = [CarNumber]
    VAR p = [Project]
    RETURN
        IF (
            CALCULATE (
                COUNTROWS ( 'Table' ),
                'Table'[From] <= d,
                'Table'[Till] >= d,
                'PQTable'[Car number] = cn,
                'PQTable'[Project] = p
            ) > 0,
            1,
            0
        )
)

14.jpg


Por cierto, pbIX archivo como adjunto.


Saludos

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-lid-msft
Community Support
Community Support

Hola @froxas ,

Podemos intentar agregar cinco pasos al final de su consulta para cumplir con sus requisitos:

como la consulta de origen como la siguiente:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8lDSUTIyMDLQNTAFIjjHTNfYAMgJMFSK1UFWBBWHcMx1DU0RigLg4ia6BobIxoI4AUZKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Car number" = _t, From = _t, Till = _t, Project = _t]),
    NameOfYourLastStep = Table.TransformColumnTypes(Source,{{"Car number", type text}, {"From", type date}, {"Till", type date}, {"Project", type text}})
in
    NameOfYourLastStep

Luego lo cambiamos a siguiente:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8lDSUTIyMDLQNTAFIjjHTNfYAMgJMFSK1UFWBBWHcMx1DU0RigLg4ia6BobIxoI4AUZKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Car number" = _t, From = _t, Till = _t, Project = _t]),
    NameOfYourLastStep = Table.TransformColumnTypes(Source,{{"Car number", type text}, {"From", type date}, {"Till", type date}, {"Project", type text}}),
    MinDate = Table.Min(NameOfYourLastStep,{"From"})[#"From"],
    MaxDate = Table.Max(NameOfYourLastStep,{"Till"})[#"Till"],
    CarNumberTable = Table.Distinct(Table.SelectColumns(NameOfYourLastStep,{"Car number","Project"})),
    DateTable = Table.ExpandListColumn(Table.AddColumn(CarNumberTable,"Date",each List.Dates(MinDate,Duration.Days(MaxDate-MinDate)+1,#duration(1,0,0,0))), "Date"),
    FinalTable = Table.AddColumn(DateTable,"Value", 
                                each let car = [Car number], pro = [Project], d = [Date] in
                                if Table.RowCount(Table.SelectRows(NameOfYourLastStep,each [Car number]=car and [Project]=pro and [From] <= d and [Till] >= d))>0 then 1 else 0)
in
    FinalTable

MinDate/MaxDate es el intervalo de fechas, luego obtenemos filas distintas para carnumber y project, agregamos cada fecha entre MinDate y MaxDate a ellos, en FinalTable, agregamos un valor para determinar si esta fecha existe en la tabla de origen.

7.jpg8.jpg9.jpg

Si no cumple con su requisito, ¿podría mostrar el resultado exacto esperado basado en las tablas que ha compartido?


Por cierto, pbIX archivo como adjunto.


Saludos

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-lid-msft gracias

esa es una solución interesante, la comprobaré.

¿existe también un método para hacerlo con DAX creando tabla? tal vez es más fácil, legible y solución mantenible?

Hola @froxas ,

Claro, podemos crear una tabla calculada para satisfacer sus necesidades:

NewTable =
ADDCOLUMNS (
    CROSSJOIN (
        DISTINCT (
            SELECTCOLUMNS ( 'Table', "CarNumber", [Car number], "Project", [Project] )
        ),
        CALENDAR ( MIN ( 'Table'[From] ), MAX ( 'Table'[Till] ) )
    ),
    "Value",
    VAR d = [Date]
    VAR cn = [CarNumber]
    VAR p = [Project]
    RETURN
        IF (
            CALCULATE (
                COUNTROWS ( 'Table' ),
                'Table'[From] <= d,
                'Table'[Till] >= d,
                'PQTable'[Car number] = cn,
                'PQTable'[Project] = p
            ) > 0,
            1,
            0
        )
)

14.jpg


Por cierto, pbIX archivo como adjunto.


Saludos

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
parry2k
Super User
Super User

@froxas cómo obtiene 0 o 1 valor en la columna de valor?



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.

@parry2k así es como necesito transformar mi mesa. Necesito crear una nueva tabla donde tengo todos los días y por cada día valor 1 si esta reservatio está en ese período.

Greg_Deckler
Super User
Super User

Creo que quieres algo como Open Tickets pero no puedes estar seguro. https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364#M147


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

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.

Top Solution Authors