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
Syndicate_Admin
Administrator
Administrator

Calcular un total en ejecución con una cantidad estática por período de fecha

Tengo una tabla que muestra la cantidad de ingresos del proyecto obtenidos durante un período de tiempo definido por los filtros del informe. El propósito es ver, de un vistazo, cuántos ingresos fueron reconocidos por proyecto por período. Al mirar las fechas actuales, esto funciona según lo previsto comparando el total de entradas de tiempo aceptadas con el presupuesto del proyecto, pero cuando se miran hacia atrás en semanas anteriores (utilizando los filtros de fecha) ignora el tiempo introducido anteriormente y solo calcula el tiempo introducido durante esa semana. Esto puede hacer que muestre que los ingresos se reconocen cuando el presupuesto del proyecto puede haber sido ya cumplido o superado.

Los filtros que me causan problemas son mis fechas[semana] y meses[mes].

Mi medida en la actualidad es:

SUMX(
 	'Projects',
	SWITCH(Projects[PM_Billing_Method_ID],
        "N", 
        CALCULATE(
            IF(CALCULATE(SUM('Time Entries'[Billable_Amt]),ALL(Dates[week]),ALL(Months[Month])) <= SUM(Projects[Billing_Amount]),
			CALCULATE(SUM('Time Entries'[Billable_Amt]),ALL(Dates[week]), ALL(Months[Month]),
                'Time Entries'[Included In Billable Hours],
                USERELATIONSHIP('Project Tickets'[TicketNbr], 'Time Entries'[SR_Service_RecID])
            ),
            CALCULATE(SUM(Projects[Billing_Amount]))
		    )
	    )
    )
)

He intentado cambiar los filtros de la medida de ALL a MAX, pero eso produce un error. Nuestros informes son generalmente bastante simples en BI y más complejos en el SQL (con los que tengo mucha más experiencia que DAX), por lo que tratar de manipular datos en BI no he hecho tanto con. Mi objetivo final sería que la tabla comparara la suma de TimeEntries[Billable_Amt] (hasta la fecha máxima permitida) con el Proyecto[Billing_Amount].

Si no hay filtros y SUM(TimeEntries[Billable_Amt]) > Project[Billing_Amount] Billing_Amt else SUM(TimeEntries[Billable_Amt]).

Si se filtra por semana o mes y SUM(TimeEntries[Billable_Amt]) (período seleccionado y versiones anteriores) menos SUM(TimeEntries[Billable_Amt] (período seleccionado)) > Proyecto[Billing_Amount] entonces 0 otro Proyecto[Billing_Amount] - SUM(TimeEntries[Billable_Amt]) (período seleccionado y anterior) + SUM(TimeEntries[Billable_Amt]) (período seleccionado)

Ex:

presupuesto (Billing_Amount) = $40,000

ingresos corrientes (SUM(TimeEntries[Billable_Amt]) (período seleccionado) = $15,000

todos los ingresos a current(SUM(TimeEntries[Billable_Amt]) (período seleccionado y anterior) = $50,000

todos los ingresos antes de current(SUM(TimeEntries[Billable_Amt]) (antes del período) = $35,000

Así que las entradas de tiempo total ($50 mil) son mayores que el presupuesto ($40 mil), pero el tiempo total de entradas menos actuales ($35 mil) no lo es, por lo que quedan ingresos de corrientes ($5 mil) para reconocer, pero no todos. No estoy seguro de cómo escribir estas medidas si no me permite utilizar la función MAX en las fechas. Con la medida actual, ya que $15 mil es menos de $40 mil, lo reconocerá todo, aunque eso no es realmente exacto.

Espero haber explicado esto lo suficientemente bien como para conseguir cualquier ayuda disponible. Si alguien puede señalarme en la dirección correcta para corregir mis errores, sería muy apreciado

Relaciones de mesa implicadas:

Fechas[Mes] *:1 Mes[Mes]

TimeEntries[Fecha] *:1 Fechas[Fecha]

TimeEntries[PM_Project_RecID] *:1 Proyectos[PM_Project_RecID]

1 ACCEPTED SOLUTION
Syndicate_Admin
Administrator
Administrator

Gracias por la ayuda y sugerencias, en última instancia pude resolver este problema.

test4 = 
VAR MaxDate = MAX(Dates[Date])
VAR MinDate = MIN(Dates[Date])
Var MaxTime = CALCULATE(SUM('Time Entries'[Billable_Amt]),'Time Entries'[Included In Billable Hours], ALL(Dates))
Var PeriodTime = CALCULATE(SUM('Time Entries'[Billable_Amt]),'Time Entries'[Included In Billable Hours], FILTER(Dates, Dates[Date] <= MaxDate && Dates[Date] >= MinDate))
Var ThroughPeriodTime = CALCULATE(SUM('Time Entries'[Billable_Amt]),'Time Entries'[Included In Billable Hours], FILTER(ALL(Dates), Dates[Date] <= MaxDate))
Var SincePeriodTime = CALCULATE(SUM('Time Entries'[Billable_Amt]),'Time Entries'[Included In Billable Hours], FILTER(ALL(Dates), Dates[Date] > MaxDate))
Var BeforePeriodTime = CALCULATE(SUM('Time Entries'[Billable_Amt]),'Time Entries'[Included In Billable Hours], FILTER(ALL(Dates), Dates[Date] < MinDate))
VAR BillingAmount = SUM(Projects[Billing_Amount])
RETURN
IF(ThroughPeriodTime < SUM(Projects[Billing_Amount]) && (HASONEFILTER(Dates[Week]) || HASONEFILTER(Dates[Month])), PeriodTime, 
    IF(BeforePeriodTime < SUM(Projects[Billing_Amount]) && (HASONEFILTER(Dates[Week]) || HASONEFILTER(Dates[Month])), BillingAmount-BeforePeriodTime, 
        IF(ThroughPeriodTime < SUM(Projects[Billing_Amount]), PeriodTime,
            IF(BeforePeriodTime < SUM(Projects[Billing_Amount]), BillingAmount-BeforePeriodTime,
                IF(BeforePeriodTime > SUM(Projects[Billing_Amount]) && (HASONEFILTER(Dates[Week]) || HASONEFILTER(Dates[Month])), 0,
                    IF(BeforePeriodTime > SUM(Projects[Billing_Amount]), BillingAmount,0
                    )
                )
            )
        )
    )    
)

View solution in original post

3 REPLIES 3
Syndicate_Admin
Administrator
Administrator

Gracias por la ayuda y sugerencias, en última instancia pude resolver este problema.

test4 = 
VAR MaxDate = MAX(Dates[Date])
VAR MinDate = MIN(Dates[Date])
Var MaxTime = CALCULATE(SUM('Time Entries'[Billable_Amt]),'Time Entries'[Included In Billable Hours], ALL(Dates))
Var PeriodTime = CALCULATE(SUM('Time Entries'[Billable_Amt]),'Time Entries'[Included In Billable Hours], FILTER(Dates, Dates[Date] <= MaxDate && Dates[Date] >= MinDate))
Var ThroughPeriodTime = CALCULATE(SUM('Time Entries'[Billable_Amt]),'Time Entries'[Included In Billable Hours], FILTER(ALL(Dates), Dates[Date] <= MaxDate))
Var SincePeriodTime = CALCULATE(SUM('Time Entries'[Billable_Amt]),'Time Entries'[Included In Billable Hours], FILTER(ALL(Dates), Dates[Date] > MaxDate))
Var BeforePeriodTime = CALCULATE(SUM('Time Entries'[Billable_Amt]),'Time Entries'[Included In Billable Hours], FILTER(ALL(Dates), Dates[Date] < MinDate))
VAR BillingAmount = SUM(Projects[Billing_Amount])
RETURN
IF(ThroughPeriodTime < SUM(Projects[Billing_Amount]) && (HASONEFILTER(Dates[Week]) || HASONEFILTER(Dates[Month])), PeriodTime, 
    IF(BeforePeriodTime < SUM(Projects[Billing_Amount]) && (HASONEFILTER(Dates[Week]) || HASONEFILTER(Dates[Month])), BillingAmount-BeforePeriodTime, 
        IF(ThroughPeriodTime < SUM(Projects[Billing_Amount]), PeriodTime,
            IF(BeforePeriodTime < SUM(Projects[Billing_Amount]), BillingAmount-BeforePeriodTime,
                IF(BeforePeriodTime > SUM(Projects[Billing_Amount]) && (HASONEFILTER(Dates[Week]) || HASONEFILTER(Dates[Month])), 0,
                    IF(BeforePeriodTime > SUM(Projects[Billing_Amount]), BillingAmount,0
                    )
                )
            )
        )
    )    
)
Syndicate_Admin
Administrator
Administrator

No @KayceVC,

¿Podría decirme si su problema ha sido resuelto? Si es así, por favor acéptelo como la solución. Más gente se beneficiará de ello. O aún así sigues confundiendo, por favor proporcióname más detalles sobre tu mesa y tu problema o compárteme con tu archivo pbix de tu Onedrive para la Empresa.

Saludos

Yuna

Syndicate_Admin
Administrator
Administrator

No @KayceVC,

¿Podría compartir sus archivos de ejemplo y el resultado esperado para tener una comprensión clara de su pregunta? Puedo hacerte algunas pruebas.

Puede guardar sus archivos en OneDrive, Google Drive o cualquier otra plataforma de uso compartido en la nube y compartir el enlace aquí.

Saludos

Yuna

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.