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
Laila92
Helper V
Helper V

Dax Measure para calcular la facturación de las transacciones activas

Tengo ofertas que tienen diferentes tipos de etapas:
Escenario en vivo

Etapa de cancelación

Etapa perdida

Escenario de incorporación.

Mis datos tienen una fecha para el inicio de cada una de estas etapas. No todos los tratos tienen una fecha de cancelación, algunos van directamente a la pérdida.
Facturamos a nuestros clientes solo cuando están en la etapa Live. Estoy tratando de escribir una medida que muestra las ofertas en vivo a lo largo del tiempo, y el dinero que estamos facturando por eso. Datos de ejemplo:

Go-Live Date Lost time ID Cancellation Request Start Date (Hide) Onboarding Start Date Monthly Price
2020-02-06 0:00:00 2020-03-03 0:00:00 17818  2020-02-04 0:00:00 $100.00
2020-02-03 0:00:00 2020-02-10 0:00:00 17468 2020-02-11 0:00:00 2020-01-31 0:00:00 $100.00
2020-02-11 0:00:00 2020-02-03 0:00:00 17469 2020-02-11 0:00:00 2020-01-31 0:00:00 $100.00
2020-01-07 0:00:00 2020-03-26 0:00:00 17150  2020-01-07 0:00:00 $400.00
2020-01-06 0:00:00 2020-03-31 0:00:00 17215 2020-03-16 0:00:00 2020-01-02 0:00:00 $849.00
2020-01-08 0:00:00 2020-03-31 0:00:00 16807 2020-02-18 0:00:00 2020-01-02 0:00:00 $150.00



Así, por ejemplo, para la identificación de la identificación 16807, quiero que la medida muestre 150$ de enero de 2020 a marzo de 2020 (450$ en total). He estado tratando de implementar esta medida discutida por @Greg_Deckler en https://community.powerbi.com/t5/Quick-Measures-Gallery/Periodic-Billing/m-p/409365, pero no puedo conseguir que funcione para mis datos.

Total Amount = 
VAR tmpCalendar = ADDCOLUMNS('Calendar',"Month",MONTH([Date]),"Year",YEAR([Date]),"MonthYear",VALUE(YEAR([Date]) & FORMAT(MONTH([Date]),"0#")))
VAR tmpBilling = ADDCOLUMNS('Billing',"MonthYearBegin",VALUE(YEAR([BeginDate]) & FORMAT(MONTH([BeginDate]),"0#")),
                                      "MonthYearEnd",VALUE(YEAR([UntilDate]) & FORMAT(MONTH([UntilDate]),"0#")))
VAR tmpTable = 
SELECTCOLUMNS(
    FILTER(
        GENERATE(
            tmpBilling,
            SUMMARIZE(tmpCalendar,[Year],[Month],[MonthYear])
        ),
        [MonthYear] >= [MonthYearBegin] &&
        [MonthYear] <= [MonthYearEnd]
    ),
    "Customer",[Customer],
    "Year",[Year],
    "Month",[Month],
    "Amount",[Amount]
)
RETURN SUMX(tmpTable,[Amount])




2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

@Laila92 - Desde que escribí eso, tal vez pueda ayudar. Vea la línea de firma adjunta debajo. ¡Avísame si necesitas más ayuda!


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

hola @Laila92

Si es así, ajuste la fórmula como se indica a continuación:

Total Amount 333 = 
VAR tmpCalendar = ADDCOLUMNS('Calendar',"Month",MONTH([Date]),"Year",YEAR([Date]),"MonthYear",VALUE(YEAR([Date]) & FORMAT(MONTH([Date]),"0#")))
VAR tmpBilling = ADDCOLUMNS('Billing',"MonthYearBegin",VALUE(YEAR([Go-Live Date]) & FORMAT(MONTH([Go-Live Date]),"0#")),
                                      "MonthYearEnd",IF(ISBLANK([Lost time]),VALUE(YEAR(TODAY()) & FORMAT(MONTH(TODAY()),"0#")),VALUE(YEAR([Lost time]) & FORMAT(MONTH([Lost time]),"0#"))))
VAR tmpTable = 
SELECTCOLUMNS(
    FILTER(
        GENERATE(
            tmpBilling,
            SUMMARIZE(tmpCalendar,[Year],[Month],[MonthYear])
        ),
        [MonthYear] >= [MonthYearBegin] &&
        [MonthYear] <= [MonthYearEnd]
    ),
    "Customer",[ID],
    "Year",[Year],
    "Month",[Month],
    "Amount",[Monthly Price]
)
RETURN SUMX(tmpTable,[Amount])

VAR tmpBilling á ADDCOLUMNS('Billing',"MonthYearBegin",VALUE(YEAR([Go-Live Date]) & FORMAT(MONTH([Go-Live Date]),"0-")),
"MonthYearEnd",IF(ISBLANK([Tiempo perdido]), VALOR (Año (HOY()) & FORMAT(MONTH(TODAY()),"0-")),VALUE(YEAR([Tiempo perdido]) & FORMAT(MONTH([Tiempo perdido]),"0-"))))

saludos

Lin

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

View solution in original post

12 REPLIES 12
Greg_Deckler
Super User
Super User

@Laila92 - Desde que escribí eso, tal vez pueda ayudar. Vea la línea de firma adjunta debajo. ¡Avísame si necesitas más ayuda!


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler ¡Necesito tu ayuda!

Usé su fórmula para calcular, pero debo tener algo mal porque el resultado es exactamente el doble de lo que se supone que debo tener.

Mi escenario es el siguiente. Tengo contratos con un ammount diario y necesito el acumulado por mes (mes fiscal). Entonces, primero generé los ingresos fiscales (multiplicando el monto diario por el número de días fiscales dentro del mes). Esto se hace con una fórmula.
Luego, utilicé su fórmula para tener el acumulativo solo en el período de virulencia.

Pero.... Debo estar haciendo algo mal porque los resultados en cada fila son el doble de los ingresos mensuales reales.

¿Alguna idea?

@AndreaMeras ¿Puede publicar datos de muestra y resultados esperados?

image.jpg

He aquí un ejemplo. Taxa es el valor diario, Fiscal days es el número de días en el mes, REv Fiscal es el valor del mes y Prod y usando su fórmula, pero como yoy puede ver, me da el doble

@Greg_Deckler Creo que el problema es que necesito una fórmula para un ammount diario en lugar de mensual. ¿Cómo puedo editar eso? ¡¡gracias!!

¡Gracias Greg! Estoy recibiendo el error "No se puede convertir el valor "" de tipo Texto a tipo Número." Supongo que esto podría deberse a que tengo valores en blanco en mis datos, pero no estoy seguro de dónde en la medida añadir var<>blank().

hola @Laila92

Sí, es que hay algún valor en blanco en la columna [Fecha de vida de salida] o en la columna [Tiempo perdido].

Así que sólo tiene que añadir un filtro como se muestra a continuación:

Importe total ?
VAR tmpCalendar á ADDCOLUMNS('Calendar',"Month",MONTH([Date]),"Year",YEAR([Date]),"MonthYear",VALUE(YEAR([Date]) & FORMAT(MONTH([Date]),"0-")))
VAR tmpBilling á ADDCOLUMNS(FILTER('Billing',Billing[Go-Live Date]<>BLANK()&&Billing[Time Lost]<>BLANK()),"MonthYearBegin",VALUE(YEAR([Go-Live Date]) & FORMAT(MONTH([Go-Live Date]),"0-")),
"MonthYearEnd",VALUE(YEAR([Tiempo perdido]) & FORMAT(MONTH([Tiempo perdido]),"0-")))
DONDE tmpTable ?
SELECTCOLUMNS(
FILTRO (
GENERAR(
tmpBilling,
RESUMIR(tmpCalendar,[Año],[Mes],[MesAño])
),
[Año de mes] > [MonthYearBegin] &&
[MonthYear] <o [MonthYearEnd]
),
"Cliente",[ID],
"Año",[Año],
"Mes",[Mes],
"Importe",[Precio mensual]
)
RETURN SUMX(tmpTable,[Amount])
saludos
Lin
Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hice el cambio y se solucionó el error, pero no veo ninguna salida de datos, cuando puse la medida en una tabla no veo ningún número. ¿Alguna idea de por qué?

hola @Laila92

Funciona bien de mi lado, por favor pruébelo, si todavía tiene el problema, por favor comparta su archivo pbix de muestra para nosotros tener una prueba.

saludos

Lin

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

Encontré el problema (estaba usando una medida para el valor de la cantidad que tenía un filtro incorrecto en él). La medida funciona ahora, sin embargo, para los clientes que no tienen una fecha perdida (que todavía están pagando actualmente), no obtengo ningún valor.
Debería construir en una condición if en la definición de tmpBilling donde si el tiempo perdido en blanco devuelve todays date.. ¿Tiene sentido?

Se vería algo como esto:

No estoy seguro de cómo implementar.

VAR tmpBilling =  
                ADDCOLUMNS( 
                    'Deals',
                        "MonthYearBegin",VALUE(YEAR([Go-Live Date]) & FORMAT(MONTH([Go-Live Date]),"0#")),
                        IF([Lost Time] = BLANK(), "MonthYearEnd" = TODAY(),"MonthYearEnd",VALUE(YEAR([Lost time]) & FORMAT(MONTH([Lost time]),"0#"))
                         )
                        )

hola @Laila92

Si es así, ajuste la fórmula como se indica a continuación:

Total Amount 333 = 
VAR tmpCalendar = ADDCOLUMNS('Calendar',"Month",MONTH([Date]),"Year",YEAR([Date]),"MonthYear",VALUE(YEAR([Date]) & FORMAT(MONTH([Date]),"0#")))
VAR tmpBilling = ADDCOLUMNS('Billing',"MonthYearBegin",VALUE(YEAR([Go-Live Date]) & FORMAT(MONTH([Go-Live Date]),"0#")),
                                      "MonthYearEnd",IF(ISBLANK([Lost time]),VALUE(YEAR(TODAY()) & FORMAT(MONTH(TODAY()),"0#")),VALUE(YEAR([Lost time]) & FORMAT(MONTH([Lost time]),"0#"))))
VAR tmpTable = 
SELECTCOLUMNS(
    FILTER(
        GENERATE(
            tmpBilling,
            SUMMARIZE(tmpCalendar,[Year],[Month],[MonthYear])
        ),
        [MonthYear] >= [MonthYearBegin] &&
        [MonthYear] <= [MonthYearEnd]
    ),
    "Customer",[ID],
    "Year",[Year],
    "Month",[Month],
    "Amount",[Monthly Price]
)
RETURN SUMX(tmpTable,[Amount])

VAR tmpBilling á ADDCOLUMNS('Billing',"MonthYearBegin",VALUE(YEAR([Go-Live Date]) & FORMAT(MONTH([Go-Live Date]),"0-")),
"MonthYearEnd",IF(ISBLANK([Tiempo perdido]), VALOR (Año (HOY()) & FORMAT(MONTH(TODAY()),"0-")),VALUE(YEAR([Tiempo perdido]) & FORMAT(MONTH([Tiempo perdido]),"0-"))))

saludos

Lin

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

La medida muestra un comportamiento inesperado para determinados identificadores. Por ejemplo, en la imagen de abajo. El precio mensual es de $899, pero el

medida muestra $44,051. Intenté reemplazar SUMX en la medida con otros, como COUNTX, pero estos tampoco devolvieron los resultados deseados. @v-lili6-msft

Capture.PNG

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.