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

Valor del último mes en la medida DAX

Esta es una continuación en este post: https://community.powerbi.com/t5/Desktop/Dax-Measure-to-calculate-Billing-of-active-deals/m-p/101388...

Tengo problemas con este poco de mi medida (la segunda en el post), la última parte de la declaración if no está regresando:

IF(ISBLANK([Lost Date]),VALUE(YEAR(TODAY()) & FORMAT(MONTH(TODAY()),"0#")),
                        IF(DAY([Lost Date]) <> 1,VALUE(YEAR([Lost Date]) & FORMAT(MONTH([Lost Date]),"0#")),
                        VALUE(YEAR(LastMonth) & FORMAT(MONTH(LastMonth),"0#"))
                        ))


Mi medida funcionaba así:

Live BILLING over time = 
VAR tmpBillingPeriod = ADDCOLUMNS(Deals_Lookup,
                "MonthYearBegin",
                IF(ISBLANK([Live Date]),VALUE(YEAR(TODAY()) & FORMAT(MONTH(TODAY()),"0#")),VALUE(YEAR([Live Date]) & FORMAT(MONTH([Live Date]),"0#"))),
                "MonthYearEnd",
                    IF(
                        ISBLANK([Lost Date]),VALUE(YEAR(TODAY()) & FORMAT(MONTH(TODAY()),"0#")),
                        VALUE(YEAR([Lost Date]) & FORMAT(MONTH([Lost Date]),"0#")))
                             )
                        )
VAR tmpTable = 
SELECTCOLUMNS(
    FILTER(
        GENERATE(
            tmpBillingPeriod,
            SUMMARIZE(Dates,[Year],[MonthNum],[MonthYearNum])
        ),
        [MonthYearNum] >= [MonthYearBegin]&&
        [MonthYearNum] <= [MonthYearEnd]
    ),
    "Customer",[ID],
    "Year",[Year],
    "Month",[MonthNum],
    "Amount",[Total Value]
)
RETURN SUMX(tmpTable,[Amount])

Sin embargo, ahora necesito incluir que SI la fecha perdida es el primer día del mes, el acuerdo no se considera EN VIVO para ese mes. Así que digamos que una fecha perdida es el 1 de abril de 2020, quiero que el último monht con facturación en vivo sea marzo de 2020. Si la fecha de pérdida es el 2 de abril, quiero incluir abril de 2020 en los meses de facturación.
Agrego otra frase IF, donde si el valor DE DIA 1, trato de restar un mes de la fecha perdida, pero no está funcionando, ver más abajo. ¿Cómo puedo arreglar esta medida?

Live MRR over time = 
VAR LastMonth =   IF (
        MONTH ( [Lost Date] ) = 1,
        /* YES */
        DATE ( YEAR ( [Lost Date] ) - 1, 12, 1 ),
        /* NO */
        DATE ( YEAR ( [Lost Date]), MONTH ( [Lost Date] ) - 1, 1 )
    )
RETURN
VAR tmpBillingPeriod = ADDCOLUMNS(Deals_Lookup,
                "MonthYearBegin",
                IF(ISBLANK([Live Date]),VALUE(YEAR(TODAY()) & FORMAT(MONTH(TODAY()),"0#")),VALUE(YEAR([Live Date]) & FORMAT(MONTH([Live Date]),"0#"))),
                "MonthYearEnd",
                    IF(ISBLANK([Lost Date]),VALUE(YEAR(TODAY()) & FORMAT(MONTH(TODAY()),"0#")),
                        IF(DAY([Lost Date]) <> 1,VALUE(YEAR([Lost Date]) & FORMAT(MONTH([Lost Date]),"0#")),
                        VALUE(YEAR(LastMonth) & FORMAT(MONTH(LastMonth),"0#"))
                        )))
VAR tmpTable = 
SELECTCOLUMNS(
    FILTER(
        GENERATE(
            tmpBillingPeriod,
            SUMMARIZE(Dates,[Year],[MonthNum],[MonthYearNum])
        ),
        [MonthYearNum] >= [MonthYearBegin]&&
        [MonthYearNum] <= [MonthYearEnd]
    ),
    "Customer",[ID],
    "Year",[Year],
    "Month",[MonthNum],
    "Amount",[Total Value]
)
RETURN SUMX(tmpTable,[Amount])


Datos de ejemplo:

ValorIdTiempo perdidoFecha de Go-Live
$1,299181942020-04-12 0:00:00
$950106222020-04-10 0:00:002018-01-31 0:00:00
$499154912020-04-07 0:00:002019-03-22 0:00:00
$0178062020-04-06 0:00:002020-03-12 0:00:00
$0178072020-04-06 0:00:002020-03-12 0:00:00
$0178082020-04-06 0:00:00
$375177692020-04-06 0:00:002020-03-12 0:00:00
$899158262020-04-06 0:00:002019-05-15 0:00:00
$899171032020-04-06 0:00:002020-01-09 0:00:00
$899172202020-04-06 0:00:002020-01-08 0:00:00
$199157582020-04-02 0:00:002019-05-02 0:00:00
$399171562020-04-01 0:00:00
$399171572020-04-01 0:00:00
$995172682020-04-01 0:00:00
1 ACCEPTED SOLUTION
v-lid-msft
Community Support
Community Support

Hola @Laila92 ,

Podemos usar la siguiente medida para satisfacer su requisito, poner el cálculo del mes anterior pasado en la función Addcolumns, ya que cuando definamos un var, el resultado será constante en lugar de diferente para cada fila en Addoculmns

Measure Live MRR over time = 
VAR tmpBillingPeriod =
    ADDCOLUMNS (
        Deals_Lookup,
        "MonthYearBegin", IF (
            ISBLANK ( [Live Date] ),
            VALUE ( YEAR ( TODAY () ) & FORMAT ( MONTH ( TODAY () ), "0#" ) ),
            VALUE ( YEAR ( [Live Date] ) & FORMAT ( MONTH ( [Live Date] ), "0#" ) )
        ),
        "MonthYearEnd", IF (
            ISBLANK ( [Lost Date] ),
            VALUE ( YEAR ( TODAY () ) & FORMAT ( MONTH ( TODAY () ), "0#" ) ),
            IF (
                DAY ( [Lost Date] ) <> 1,
                VALUE ( YEAR ( [Lost Date] ) & FORMAT ( MONTH ( [Lost Date] ), "0#" ) ),
                VALUE (
                    YEAR ( DATE ( YEAR ( [Lost Date] ), MONTH ( [Lost Date] ) - 1, 1 ) )
                        & FORMAT (
                            MONTH ( DATE ( YEAR ( [Lost Date] ), MONTH ( [Lost Date] ) - 1, 1 ) ),
                            "0#"
                        )
                )
            )
        )
    )
VAR tmpTable =
    SELECTCOLUMNS (
        FILTER (
            GENERATE (
                tmpBillingPeriod,
                SUMMARIZE ( Dates, [Year], [MonthNum], [MonthYearNum] )
            ),
            [MonthYearNum] >= [MonthYearBegin]
                && [MonthYearNum] <= [MonthYearEnd]
        ),
        "Customer", [ID],
        "Year", [Year],
        "Month", [MonthNum],
        "Amount", [Value]
    )
RETURN
SUMX ( tmpTable, [Amount] )

Mediante el uso de sus datos de muestra, podemos obtener el resultado de esta manera,

13.jpg

Si no cumple con su requisito, ¿podría mostrar el resultado exacto esperado basado en las tablas que ha compartido?

BTW, pbix como adjunto.

Saludos

Community Support Team _ Dong Li
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

1 REPLY 1
v-lid-msft
Community Support
Community Support

Hola @Laila92 ,

Podemos usar la siguiente medida para satisfacer su requisito, poner el cálculo del mes anterior pasado en la función Addcolumns, ya que cuando definamos un var, el resultado será constante en lugar de diferente para cada fila en Addoculmns

Measure Live MRR over time = 
VAR tmpBillingPeriod =
    ADDCOLUMNS (
        Deals_Lookup,
        "MonthYearBegin", IF (
            ISBLANK ( [Live Date] ),
            VALUE ( YEAR ( TODAY () ) & FORMAT ( MONTH ( TODAY () ), "0#" ) ),
            VALUE ( YEAR ( [Live Date] ) & FORMAT ( MONTH ( [Live Date] ), "0#" ) )
        ),
        "MonthYearEnd", IF (
            ISBLANK ( [Lost Date] ),
            VALUE ( YEAR ( TODAY () ) & FORMAT ( MONTH ( TODAY () ), "0#" ) ),
            IF (
                DAY ( [Lost Date] ) <> 1,
                VALUE ( YEAR ( [Lost Date] ) & FORMAT ( MONTH ( [Lost Date] ), "0#" ) ),
                VALUE (
                    YEAR ( DATE ( YEAR ( [Lost Date] ), MONTH ( [Lost Date] ) - 1, 1 ) )
                        & FORMAT (
                            MONTH ( DATE ( YEAR ( [Lost Date] ), MONTH ( [Lost Date] ) - 1, 1 ) ),
                            "0#"
                        )
                )
            )
        )
    )
VAR tmpTable =
    SELECTCOLUMNS (
        FILTER (
            GENERATE (
                tmpBillingPeriod,
                SUMMARIZE ( Dates, [Year], [MonthNum], [MonthYearNum] )
            ),
            [MonthYearNum] >= [MonthYearBegin]
                && [MonthYearNum] <= [MonthYearEnd]
        ),
        "Customer", [ID],
        "Year", [Year],
        "Month", [MonthNum],
        "Amount", [Value]
    )
RETURN
SUMX ( tmpTable, [Amount] )

Mediante el uso de sus datos de muestra, podemos obtener el resultado de esta manera,

13.jpg

Si no cumple con su requisito, ¿podría mostrar el resultado exacto esperado basado en las tablas que ha compartido?

BTW, pbix como adjunto.

Saludos

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

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.