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
silveiralopesa
New Member

Dax de calculo

Bom dia a todos!

Eu estou tentando há alguns dias fazer a soma acumulativa de uma coluna no power bi que recomeçe a soma do zero quando o valor de outra coluna (na mesma linha) seja TRUE. No momento que consegui fazer a soma acumulativa e colocar zero nas linhas que tem o valor true, mas ela não reinicia a contagem da soma acumulativa após o zero, como deveria. Aqui esta a dax que tenho até agora. Alguém poderia me ajudar a fazer essa soma acumulativa da maneira correta?
Obrigado desde já.

SomaAcumulativaBotrytis =
VAR DataAtual = Donnes_SERRE1_2021_2023_test[Date]
RETURN
    IF(
        Donnes_SERRE1_2021_2023_test[Applications fongicides] = TRUE,
     0 
        ),
        CALCULATE(
            SUMX(
                FILTER(
                    ALL(Donnes_SERRE1_2021_2023_test),
                    Donnes_SERRE1_2021_2023_test[Date] <= DataAtual &&
                    Donnes_SERRE1_2021_2023_test[Applications fongicides] <> 1
                ),
                Donnes_SERRE1_2021_2023_test[ColuneBotrytis]
            )
        )
    )
2 REPLIES 2
swikritee_p
Resolver II
Resolver II

@silveiralopesa , Try if this calculation can help

CumulativeSumBotrytis =
VAR CurrentDate = Donnes_SERRE1_2021_2023_test[Date]
VAR ResetGroup_ = 
    CALCULATE(
        COUNTROWS(
            FILTER(
                ALL(Donnes_SERRE1_2021_2023_test),
                Donnes_SERRE1_2021_2023_test[Date] <= CurrentDate && 
                Donnes_SERRE1_2021_2023_test[Fungicide applications] = TRUE
            )
        ),
        ALL(Donnes_SERRE1_2021_2023_test)
    )
RETURN
    CALCULATE(
        SUMX(
            FILTER(
                ALL(Donnes_SERRE1_2021_2023_test),
                Donnes_SERRE1_2021_2023_test[Date] <= CurrentDate &&
                CALCULATE(
                    COUNTROWS(
                        FILTER(
                            ALL(Donnes_SERRE1_2021_2023_test),
                            Donnes_SERRE1_2021_2023_test[Date] <= CurrentDate && 
                            Donnes_SERRE1_2021_2023_test[Fungicide applications] = TRUE
                        )
                    ),
                    ALL(Donnes_SERRE1_2021_2023_test)
                ) = ResetGroup_
            ),
            Donnes_SERRE1_2021_2023_test[ColuneBotrytis]
        )
    )

Hello swikritee_p, thanks for the answer, the cumulative sum works well, BUT it doesnt restarts when the value in the "Applications fongiques" column is "True". For each day we have more then one value in the column "ColuneBotrytis" (one value for each 30 minutes in the day). In the column "Applications fongiques", the "TRUE" or "FALSE" value is repeated in all rows concerning the same date. Maybe this requests a change in the DAX?

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

March 2024 PBI Gallery Image

Power BI Monthly Update - March 2024

Check out the March 2024 Power BI update to learn about new features.