Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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?
Solved! Go to 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
)
)
Por cierto, pbIX archivo como adjunto.
Saludos
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.
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
@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
)
)
Por cierto, pbIX archivo como adjunto.
Saludos
@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.
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