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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Columna con el valor máximo de otra según condición

Hola!!

Necesito ayuda con un calculo, tengo una tabla con dos campos, el primero es una id que se puede repetir en otras filas, la segunda tiene el monto total que puede ser distinto en cada fila. Lo que necesito es crear un nuevo campo que me rescate el valor maximo para cada ID y me deje en cero las que tengan el valor minimo.

 

Ejemplo:

 

IDMontoTotal
A1000
A1500
A170170
B500
B8080
C2000
C250250
D1010

 

Ojalá se entienda, muchas gracias.

1 ACCEPTED SOLUTION
Syndicate_Admin
Administrator
Administrator

No hay @Syndicate_Admin

Si necesita una columna en M

Vera_33_0-1617246956289.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0MFCK1YGyTZHY5hC2E5BtimBaQJjOQKaRARIbqsQFbKJSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Amount", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Total_m", each List.Max([Amount]), type nullable number}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"ID"}, #"Grouped Rows", {"ID"}, "Grouped Rows", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(#"Merged Queries", "Total_m", each if [Amount]=[Grouped Rows][Total_m]{0} then [Grouped Rows][Total_m]{0} else 0)
in
    #"Added Custom"

O columna DAX

Vera_33_1-1617247029862.png

Total = 
VAR CurID = 'Table'[ID]
VAR MaxAmount = MAXX(FILTER('Table','Table'[ID]=CurID),'Table'[Amount])
RETURN
IF('Table'[Amount]=MaxAmount,'Table'[Amount],0)

View solution in original post

5 REPLIES 5
Syndicate_Admin
Administrator
Administrator

No @Syndicate_Admin,

Intente crear una medida o calcular la columna

Medida:

Measure =
VAR maxAmoout = CALCULATE(
    MAX('Table'[Amount]),FILTER(ALL('Table'),'Table'[ID]= MAX('Table'[ID]))
)
RETURN
IF(maxAmoout = SUM('Table'[Amount]),maxAmoout,0)

Calcular columna:

Column =
VAR MaxAmount =
    CALCULATE (
        MAX ( 'Table'[Amount] ),
        FILTER ( ALL ( 'Table' ), 'Table'[ID] = EARLIER ( 'Table'[ID] ) )
    )
RETURN
    IF ( 'Table'[Amount] = MaxAmount, 'Table'[Amount], 0 )

Datos de muestra:

v-angzheng-msft_0-1617355720632.png

Resultado:

v-angzheng-msft_1-1617355720775.jpeg

¿Es este el resultado que quieres? Espero que esto sea útil para ti

Por favor, no dude en avisarme Si tiene más preguntas

Saludos
Equipo de Apoyo a la Comunidad _ Zeon Zheng
Si este post ayuda, entonces considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

Buen día,

 

Por favor su ayuda, que pasaría si el monto total se repite en una misma id la idea es dejar un solo resultado

Edwincv_0-1701868455191.png

Gracias por su ayuda

Syndicate_Admin
Administrator
Administrator

Hola

Por favor, pruebe la siguiente medida.

Máximo para cada ID =
CORRIENTE VARID =
SELECTEDVALUE ( 'Tabla'[ID] )
Var groupbytable =
FILTRO (
GROUPBY (
ALL ( 'Tabla'),
'Tabla'[ID],
"@maxamount", MAXX ( CURRENTGROUP (), 'Tabla'[Importe] )
),
'Tabla'[ID] = currentID
)
devolución
IF (
SELECTEDVALUE ( 'Tabla'[Importe] ) = SUMX ( groupbytable, [@maxamount] ),
SUMX (groupbytable, [@maxamount]),
0
)

Hola, mi nombre es Jihwan Kim.

Si este post ayuda, considere aceptarlo como la solución para ayudar a otros miembros a encontrarlo más rápido.

Syndicate_Admin
Administrator
Administrator

No hay @Syndicate_Admin

Si necesita una columna en M

Vera_33_0-1617246956289.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0MFCK1YGyTZHY5hC2E5BtimBaQJjOQKaRARIbqsQFbKJSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Amount", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Total_m", each List.Max([Amount]), type nullable number}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"ID"}, #"Grouped Rows", {"ID"}, "Grouped Rows", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(#"Merged Queries", "Total_m", each if [Amount]=[Grouped Rows][Total_m]{0} then [Grouped Rows][Total_m]{0} else 0)
in
    #"Added Custom"

O columna DAX

Vera_33_1-1617247029862.png

Total = 
VAR CurID = 'Table'[ID]
VAR MaxAmount = MAXX(FILTER('Table','Table'[ID]=CurID),'Table'[Amount])
RETURN
IF('Table'[Amount]=MaxAmount,'Table'[Amount],0)

Anonymous
Not applicable

Muchas gracias!!! utilicé la columna DAX y funcionó perfecto.

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

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