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

We'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

Reply
Syndicate_Admin
Administrator
Administrator

Aparición de la primera bandera con filtro y desempate

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

CuentaCreateDate (Fecha de creación)ActivoFirstOccurrence
X15-Mar-241
X15-Mar-240
Y14-Mar-24No0
Y15-Mar-241
1 REPLY 1
Syndicate_Admin
Administrator
Administrator

Hola @dorukturkoglu ,

En función de la muestra y la descripción que proporcionó, pruebe los siguientes pasos:
Mi muestra:

vweiyan1msft_0-1710832330802.png

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"

vweiyan1msft_1-1710832370702.png

vweiyan1msft_2-1710832456611.png

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.

vweiyan1msft_3-1710832504182.png

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

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.

Top Kudoed Authors