Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Icon for Administrator rankAdministrator
5 years ago
Solved

AddColumns con Resumir

Hola a todos

Novato aquí buscando orientación. Estoy tratando de averiguar cuál es el mejor enfoque de DAX para resolver el siguiente problema. Cualquier ayuda de expertos en esta comunidad es muy apreciada.

Tengo una tabla con la que se tienen los datos del parte de horas enviados por los empleados para registrar el tiempo que dedican a los clientes. Mi objetivo es asignar proporcionalmente el costo de cada empleado a las respectivas cuentas de clientes en las que trabajaron. La salida simplemente mostrará dos columnas Clientes y Costo de mano de obra asignado. Aquí hay una instantánea de cómo lo estoy haciendo en Excel ahora. Intenté usar SummarizeColumns con AddColumns, pero no pude averiguar el código DAX. Gracias

gpillai99_0-1630848195051.png

  • @gpillai99,

    Pruebe esta solución.

    1. Modelo de datos:

    DataInsights_0-1630862101316.png

    2. Medidas:

    Billable Hours = SUM ( LaborHours[Billable Hours] )
    
    Non-Billable Hours = SUM ( LaborHours[Non-Billable Hours] )
    
    Allocated Labor Cost = 
    VAR vBaseTable =
        ADDCOLUMNS (
            SUMMARIZE (
                LaborHours,
                Customer[Customer ID],
                Employee[Employee ID],
                Employee[Labor Cost]
            ),
            "@CustomerHours", [Billable Hours] + [Non-Billable Hours]
        )
    VAR vEmpHoursTable =
        ADDCOLUMNS (
            vBaseTable,
            "@EmployeeHoursTotal", CALCULATE ( [Billable Hours] + [Non-Billable Hours], ALL ( Customer ) )
        )
    VAR vPercentTable =
        ADDCOLUMNS (
            vEmpHoursTable,
            "@Percent", DIVIDE ( [@CustomerHours], [@EmployeeHoursTotal] )
        )
    VAR vAllocationTable =
        ADDCOLUMNS ( vPercentTable, "@Allocation", [@Percent] * Employee[Labor Cost] )
    VAR vResult =
        SUMX ( vAllocationTable, [@Allocation] )
    RETURN
        vResult

    3. Crear visual usando Customer[Customer ID]:

    DataInsights_1-1630862153174.png

2 Replies

  • @gpillai99,

    Pruebe esta solución.

    1. Modelo de datos:

    DataInsights_0-1630862101316.png

    2. Medidas:

    Billable Hours = SUM ( LaborHours[Billable Hours] )
    
    Non-Billable Hours = SUM ( LaborHours[Non-Billable Hours] )
    
    Allocated Labor Cost = 
    VAR vBaseTable =
        ADDCOLUMNS (
            SUMMARIZE (
                LaborHours,
                Customer[Customer ID],
                Employee[Employee ID],
                Employee[Labor Cost]
            ),
            "@CustomerHours", [Billable Hours] + [Non-Billable Hours]
        )
    VAR vEmpHoursTable =
        ADDCOLUMNS (
            vBaseTable,
            "@EmployeeHoursTotal", CALCULATE ( [Billable Hours] + [Non-Billable Hours], ALL ( Customer ) )
        )
    VAR vPercentTable =
        ADDCOLUMNS (
            vEmpHoursTable,
            "@Percent", DIVIDE ( [@CustomerHours], [@EmployeeHoursTotal] )
        )
    VAR vAllocationTable =
        ADDCOLUMNS ( vPercentTable, "@Allocation", [@Percent] * Employee[Labor Cost] )
    VAR vResult =
        SUMX ( vAllocationTable, [@Allocation] )
    RETURN
        vResult

    3. Crear visual usando Customer[Customer ID]:

    DataInsights_1-1630862153174.png

    • Syndicate_Admin's avatar
      Syndicate_Admin
      Icon for Administrator rankAdministrator

      Sí, esto está muy claro y funciona perfectamente. ¡Gracias!