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

cumulative sum of a column in Power BI

Good morning, everyone!

I have been trying for a few days to perform the cumulative sum of a column in Power BI that resets the sum to zero when the value in another column (in the same row) is TRUE. At the moment, I managed to perform the cumulative sum and set zero for the rows that have the TRUE value, but it does not restart the cumulative sum after zero, as it should. Here is the DAX code I have so far. Could someone help me perform this cumulative sum correctly? Thank you in advance.


CumulativeSumBotrytis =
VAR CurrentDate = 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] <= CurrentDate &&
Donnes_SERRE1_2021_2023_test[Applications fongicides] <> 1
),
Donnes_SERRE1_2021_2023_test[ColuneBotrytis]
)
)
)

3 REPLIES 3
Sahir_Maharaj
Super User
Super User

Hello @silveiralopesa,

 

I have revised your DAX measure. Can you please try this:

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[Applications fongicides] = TRUE
                && Donnes_SERRE1_2021_2023_test[Date] <= CurrentDate
            )
        )
    )
RETURN
    CALCULATE(
        SUM(Donnes_SERRE1_2021_2023_test[ColuneBotrytis]),
        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[Applications fongicides] = TRUE
                        && Donnes_SERRE1_2021_2023_test[Date] <= Donnes_SERRE1_2021_2023_test[Date]
                    )
                )
            ) = ResetGroup
        )
    )

 

Should you have any questions, please do not hesitate to reach out to me.


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

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution?
➤ Lets connect on LinkedIn: Join my network of 13K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

thanks for the answer! BUT it gives me just blank spaces in the new column. 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?

This DAX resulted in blank spaces only 😑

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.

Top Solution Authors