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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
BasB
Regular Visitor

Cómo presentar una clave de varios campos incompleta en un campo de columna

En mi modelo de datos tengo una combinación de campos que coinciden con entre dos tablas.

La tabla Tranasction

OrgOficinaGrupo
AN01HH01F01
AN01HH02G03
BO02KL03N03
GR01NN01J01
FD02KL01H01

La tabla de precios

Level_1Level_2Level_3
AN01
BO02
GR01NN01
FD02KL01H01

Sin embargo, en la tabla de precios algunas líneas no tienen todos los campos definidos.

De hecho, la primera línea de la tabla de precios coincidirá con todas las transacciones en las que Org Level_1 (AN01 - AN01)

Mientras que en el caso de la tercera línea de la tabla de precios el enlace entre las dos tablas se basa en 2 columnas:

La organización es Level_1 (GR01 a GR01) y la oficina Level_2 (NN01 a NN01)

Mientras que en el caso de la última línea de la tabla de precios el enlace entre las dos tablas se basa en 3 columnas:

La organización es Level_1 (GR01 a GR01) y la oficina Level_2 (NN01 a NN01) y el grupo Level_3 (H01 a H01)

De hecho, el nivel más bajo de detalle es el interlineado, si no es posible obtener un nivel inferior se debe aplicar el nivel más alto.

¿Cómo se puede compilar esto en esta definición de columna:

Country_Price = 
var _dt = maxx(
  filter(
    Price,
    Price[ProductID] = Transaction[ProductID]
    && Price[Level_1] = Transaction[Org]
    && Price[Level_2] = Transaction[Office]
    && Price[Level_3] = Transaction[Group]
    && Price[Date_valid_from] < Transaction[Date]
    && Price[Type of Price] = "Country"
  ),
  Price[Date_valid_from]
)
return maxx(
  filter(
    Price,
    Price[ProductID] = Transaction[ProductID] 
    && Price[Level_1] = Transaction[Org]
    && Price[Level_2] = Transaction[Office]
    && Price[Level_3] = Transaction[Group]
    && Price[Date_valid_from] = _dt
    && Price[Type of Price] = "Country"
  ),
  Price [Price]
)

2 REPLIES 2
BasB
Regular Visitor

He encontrado una solución:

Country_Price = 
var _dt = maxx(
  filter(
    Price,
    Price[ProductID] = Transaction[ProductID]
    && if(
      Price[Level_3] = BLANK(),
      if(Price[Level_2] = BLANK(),
        Price[Level_1] = Transaction[Org],
        Price[Level_1] = Transaction[Org]
        && Price[Level_2] = Transaction[Office]
      ),
      Price[Level_1] = Transaction[Org]
      && Price[Level_2] = Transaction[Office]
      && Price[Level_3] = Transaction[Group]
    )
     && Price[Date_valid_from] < Transaction[Date]
    && Price[Type of Price] = "Country"
  ),
  Price[Date_valid_from]
)
return maxx(
  filter(
    Price,
    Price[ProductID] = Transaction[ProductID] 
    && if(
      Price[Level_3] = BLANK(),
      if(Price[Level_2] = BLANK(),
        Price[Level_1] = Transaction[Org],
        Price[Level_1] = Transaction[Org]
        && Price[Level_2] = Transaction[Office]
      ),
      Price[Level_1] = Transaction[Org]
      && Price[Level_2] = Transaction[Office]
      && Price[Level_3] = Transaction[Group]
    )
    && Price[Date_valid_from] = _dt
    && Price[Type of Price] = "Country"
  ),
  Price [Price]
)
v-eachen-msft
Community Support
Community Support

Hola @BasB ,

¿Podría compartir sus datos de muestra y el resultado esperado para mí si no tiene ninguna información confidencial? Cargue sus archivos en OneDrive para la Empresa y comparta el enlace aquí.

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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