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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
joshua1990
Post Prodigy
Post Prodigy

LDM de varios niveles con un maestro de artículos

¡Hola a todos!

Necesito incluir una lista de materiales de varios niveles en mi modelo de datos.

Tengo un maestro de artículos que contiene todos los atributos de cada elemento:

ArtículoUnidadAttr1Attr2Attr3Attr4
A1
A2

Entonces tengo una lista de materiales como:

Elemento principalArtículo infantilValorUnidad
A1A2XX
A1A3XX
A2A4XX

Como puede ver, el maestro de elementos tiene todos los elementos primarios y secundarios.

Ahora, ¿cómo vincularía esa lista de materiales del maestro de artículos?

Asumo que necesito una relación con el elemento principal Y con el elemento secundario, pero solo uno puede estar activo.

¿Alguien tiene alguna sugerencia?

2 REPLIES 2
edhans
Super User
Super User

Hola @joshua1990

Tienes al menos dos opciones aquí.

  1. Puede utilizar la función PATH() en DAX, que le permitirá trabajar a través de las herencias padre/hijo. Hay un artículo sobre él en SQLBI.
  2. Como alternativa, puede modelar esto en Power Query para despivot las columnas de elemento, convirtiendo esto:
    1. edhans_0-1594504017088.png

    2. en esto:
    3. edhans_1-1594504075134.png

La nueva tabla de Power Query ahora le permitiría hacer que su tabla de DIM de elemento filtre su número de artículo aquí como una relación de 1 a muchos y, a continuación, simplemente usaría algo como esto para obtener elementos primarios/secundarios específicos:

Parent Totals = 
SUMX(
    FILTER(
        'Table',
        'Table'[Item Attribute] = "Parent Item"
    ),
    'Table'[Value]
)

La transformación de código M completa está a continuación, pero básicamente acabo de seleccionar las columnas Padre/Hijo, hice clic con el botón derecho y seleccioné COLUMNAS UNPIVOT seleccionadas.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRU0lFyNAISIIalpVKsDkzQGEiAJCwsIIIgtqMJkABJmJsrxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Parent Item" = _t, #"Child Item" = _t, Value = _t, Unit = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Parent Item", type text}, {"Child Item", type text}, {"Value", Int64.Type}, {"Unit", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Value", "Unit"}, "Item Atribute", "Item Number"),
    #"Reordered Columns" = Table.ReorderColumns(#"Unpivoted Columns",{"Item Atribute", "Item Number", "Value", "Unit"})
in
    #"Reordered Columns"

1) En Power Query, seleccione Nueva fuente y, a continuación, Consulta en blanco
2) En la cinta de opciones Inicio, seleccione el botón "Editor avanzado"
3) Retire todo lo que ve, luego pegue el código M que le he dado en esa caja.
4) Pulse Hecho
5) Consulte este artículo si necesita ayuda para usar este código M en su modelo.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
kentyler
Solution Sage
Solution Sage

DAX no admite jerarquías de forma nativa. Sin embargo, puede hacer cosas como listas de materiales, tiene que crear algunas columnas calculadas para que funcionen. Aquí está el patrón para ese problema, que incluye ejemplos de código y una explicación paso a paso.





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

Check out the April 2025 Power BI update to learn about new features.

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors
Top Kudoed Authors