Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext 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
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:
| ID | Monto | Total |
| A | 100 | 0 |
| A | 150 | 0 |
| A | 170 | 170 |
| B | 50 | 0 |
| B | 80 | 80 |
| C | 200 | 0 |
| C | 250 | 250 |
| D | 10 | 10 |
Ojalá se entienda, muchas gracias.
Solved! Go to Solution.
Si necesita una columna en M
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
Total =
VAR CurID = 'Table'[ID]
VAR MaxAmount = MAXX(FILTER('Table','Table'[ID]=CurID),'Table'[Amount])
RETURN
IF('Table'[Amount]=MaxAmount,'Table'[Amount],0)
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:
Resultado:
¿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
Gracias por su ayuda
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.
Si necesita una columna en M
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
Total =
VAR CurID = 'Table'[ID]
VAR MaxAmount = MAXX(FILTER('Table','Table'[ID]=CurID),'Table'[Amount])
RETURN
IF('Table'[Amount]=MaxAmount,'Table'[Amount],0)
Muchas gracias!!! utilicé la columna DAX y funcionó perfecto.
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.
Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.