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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
pfz
New Member

dividir valores específicos basados en los valores de dos columnas y agregar a otras filas

Hola

Tengo una tabla con tres columnas: fecha, centro de trabajo y SpentHours

FechaWorkcenterSpentHours
01/01/2020100.DTC30
01/01/2020100.d102100
01/01/2020100.D103150
01/01/2020100.D202200
01/01/2020100.DFT20
01/01/2020100.DPT10

Necesito dividir las horas de un centro de trabajo específico y agregarlas a otras en función de la columna de fecha. Así, por ejemplo, para una fecha específica (01/01/2020) necesito:

1. Dividir las 20 horas del centro de trabajo 100. DFT en 3 partes y añadir al centro de trabajo 100.D102 dos tercios y un tercio a 100.D103

2. añadir las horas del centro de trabajo 100.DPT al centro de trabajo 100.D102

3. Dividir las horas del centro de trabajo 100.DTC en 3 partes y añadir a los centros de trabajo 100.D102, 100.D103 y 100.D202 un tercio cada

Y, por supuesto, necesito replicar estas divisiones a otros días en la columna Fecha

3 REPLIES 3
Anonymous
Not applicable

Hola @pfz ,

Puede seguir los siguientes pasos para lograrlo:

1. Crear una tabla de reglas "Divididas"

rule table.JPG

2. Cree una columna calculada con la siguiente fórmula:

Column = 
var _DFT=CALCULATE(MAX('Splits'[DFT]),FILTER('Splits','Splits'[Workcenter]=EARLIER('Spent hours'[Workcenter])))
var _DPT=CALCULATE(MAX('Splits'[DPT]),FILTER('Splits','Splits'[Workcenter]=EARLIER('Spent hours'[Workcenter])))
var _DTC=CALCULATE(MAX('Splits'[DTC]),FILTER('Splits','Splits'[Workcenter]=EARLIER('Spent hours'[Workcenter])))
var _DFTSH=CALCULATE(MAX('Spent hours'[SpentHours]),FILTER('Spent hours','Spent hours'[Workcenter]="100.DFT"&&'Spent hours'[Date]=EARLIER('Spent hours'[Date])))
var _DPTSH=CALCULATE(MAX('Spent hours'[SpentHours]),FILTER('Spent hours','Spent hours'[Workcenter]="100.DPT"&&'Spent hours'[Date]=EARLIER('Spent hours'[Date])))
var _DTCSH=CALCULATE(MAX('Spent hours'[SpentHours]),FILTER('Spent hours','Spent hours'[Workcenter]="100.DTC"&&'Spent hours'[Date]=EARLIER('Spent hours'[Date])))
return IF('Spent hours'[Workcenter] in {"100.DFT","100.DPT","100.DTC"},BLANK(),'Spent hours'[SpentHours]+_DFT*_DFTSH+_DPT*_DPTSH+_DTC*_DTCSH)

splits.JPG

Saludos

Rena

AllisonKennedy
Community Champion
Community Champion

DAX realmente no realiza cálculos de fila individuales, por lo que tendrá que crear una tabla que tenga las instrucciones codificadas de forma rígida en ella y, a continuación, usarla en los cálculos de DAX.

Estoy pensando algo como:

FuenteDestinoCantidad
100.DFT100.D1021/3
100.DFT100.D1032/3
100.DPT100.D1021
100.DTC100.D1021/3
100.DTC100.D1031/3
100.DTC100.D2021/3

A continuación, tendrá que hacer algunos filtros DAX, comparaciones y cálculos para que funcione, pero debe ser capaz de llegar allí.

Si no puede articular lo que necesita en una tabla como la anterior, tendrá problemas para hacerlo en Power BI.


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

TomMartens
Super User
Super User

Hola @pfz ,

aquí está mi enfoque.

Primero creé una tabla "AllocationRules" que describe cómo spenthourshours of Workcenter (Sender) se dividirá o asignará a otro workcenter (Receiver).
Para evitar problemas de redondeo pienso en partes.

Dentro de la medida Asignación hay una variable que suma todas las partes y crea una fracción.
Si no se asignará el 100% de Hourspent, se puede utilizar una fila con un receptor vacío para configurar esto.
image.png
La medida Asignación (en mi ejemplo nombré a la tabla "Hecho"):

Allocation = 
var t =
    SUMMARIZE(
        'Fact'
        , 'Fact'[Date]
        , 'Fact'[Workcenter]
    )
return
SUMX(
    t
    , var __workcenter = 'Fact'[Workcenter]
    var __date = 'Fact'[Date]
    var allsender = 
        CALCULATETABLE(
            FILTER('AllocationRules' , 'AllocationRules'[Receiver] = __workcenter)
            , ALL(AllocationRules[Sender])
        )
    var noOfReceivings = COUNTROWS(allsender)
    return
    IF(noOfReceivings > 0 
        , SUMX(
            allsender
            , var __sender = 'AllocationRules'[Sender]
            var hoursspent = CALCULATE(SUM('Fact'[Spenthours]) , 'Fact'[Date] = __date , 'Fact'[Workcenter] = __sender)
            var allparts =
                CALCULATE( 
                    CALCULATE(
                        SUM('AllocationRules'[Part])         
                        , 'AllocationRules'[Sender] = __sender
                    ) 
                    , ALL(AllocationRules)
                )
            return
            ('AllocationRules'[Part] / allparts) * hoursspent
        ) 
        , BLANK()
    )
) 

Y un objeto visual de mesa:
image.png
Tenga en cuenta que no se tienen en cuenta los cambios de reglas de asignación a lo largo del tiempo, pero básicamente funcionará, entonces es necesario identificar la regla de asignación que es válida en un momento dado en el tiempo.

Con suerte, esto ayuda a crear una solución.

saludos
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

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