Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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.
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.