Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hola, quiero marcar la primera aparición de cuentas en función de una fecha, con un filtro (solo debe considerar si ACTIVE=yes), y si hay duplicados necesito elegir solo uno de ellos (al azar).
El trabajo esperado es el siguiente
| Cuenta | CreateDate (Fecha de creación) | Activo | FirstOccurrence |
| X | 15-Mar-24 | Sí | 1 |
| X | 15-Mar-24 | Sí | 0 |
| Y | 14-Mar-24 | No | 0 |
| Y | 15-Mar-24 | Sí | 1 |
Hola @dorukturkoglu ,
En función de la muestra y la descripción que proporcionó, pruebe los siguientes pasos:
Mi muestra:
1.Puede considerar la posibilidad de agregar una columna de índice en Power Query.
El código específico es el siguiente.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WilDSUTI01fVNLNI1MgGyI1OLlWJ1CIibYYpHgsRNEOJ++QhhLMZEYjMmFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Account = _t, CreateDate = _t, Active = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Account", type text}, {"CreateDate", type date}, {"Active", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Account"}, {{"Count", each Table.AddIndexColumn(_, "Index", 1, 1, Int64.Type)}}),
#"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"CreateDate", "Active", "Index"}, {"CreateDate", "Active", "Index"})
in
#"Expanded Count"
2.Utilice el siguiente código para crear una columna calculada.
FirstOccurrence =
VAR CurrentAccount = 'Table'[Account]
VAR CurrentDate = 'Table'[CreateDate]
VAR MinDate =
CALCULATE (
MIN ( 'Table'[CreateDate] ),
FILTER (
ALL ( 'Table' ),
'Table'[Account] = CurrentAccount
&& 'Table'[Active] = "Yes"
)
)
VAR MinIndex =
CALCULATE (
MIN ( 'Table'[Index] ),
FILTER (
'Table',
'Table'[Account] = CurrentAccount
&& 'Table'[CreateDate] = MinDate
)
)
RETURN
IF ( 'Table'[CreateDate] = MinDate && 'Table'[Index] = MinIndex, 1, 0 )
El resultado es el siguiente.
¿Es este el resultado que esperas?
Para más detalles, sírvase encontrar el archivo adjunto.
Saludos
Yulia Yan
Si esta publicación ayuda, considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.