Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
game1
Helper III
Helper III

How to build a cumulative graph

I want to build a cumulative graph of the Items column. The problem is that currently, I would like if the date does not exist in the Date column, to still continue the cumulative calculation until today's date. Currently, the cumulative will display the value 2 for the date 2024-03-20, then continue with the date 2024-03-22 with the value 3. So, there are not the date 2024-03-21. But, I want that at 2024-03-21, it will return the value 2. 
THANKS.

 

image.png

It must give sommething like this: 

Capture d’écran, le 2024-04-02 à 00.27.53.png

2 ACCEPTED SOLUTIONS
DAX_Machine
Frequent Visitor

Good Morning, 
do You have a DateTable ? 
if not you can create one by using this code:

DIM_Datetable =
VAR calender =

CALENDAR(
Date( 2020,01,01 -- FirstDate
),
DATE(
2030,01,01 -- Last Date
)
)

RETURN

ADDCOLUMNS(
calender,
Year,YEAR([Date]),
Quarter, CONCATENATE(Q,QUARTER([Date])),
Year Month, YEAR([Date]) & - & FORMAT(MONTH([Date]), 00),
Month, MONTH([Date]),
Month Name, FORMAT([Date], MMMM),
Day of year, DATEDIFF(DATE(YEAR([Date]),1,1),[Date],DAY)+1,
Day of Month, DAY([Date]),
Day of week, WEEKDAY([Date],2),
Day Name, FORMAT([Date], DDDD),
Weeknum, FORMAT(WEEKNUM([Date],2),00),
Year Weeknum, YEAR([Date]) & FORMAT(WEEKNUM([Date],2),00),
Year Quarter, YEAR([Date]) & - & QUARTER([Date])
)

This code will create a date table including the dates you specify. After creating this table You can connect it with your fact table by a one to many relationship then use the date table instead of your date column in your graph.

Let me know if this was useful!

View solution in original post

Joe_Barry
Super User
Super User

Hi @game1 

 

There are two possibilities. The first one will require a date table as @DAX_Machine  suggested. When the data model is set up correctly you can use the Date from the Date table in the visual and then add this measure

 

RunningTotal =
VAR MaxDate =
    MAX ( DIM_Date[Date] )
RETURN
    CALCULATE (
        COUNTROWS(Table),
        KEEPFILTERS ( 'Table'[Date] <= MaxDate
            && 'Table'[Date] >= MaxDate,
        ALL ( DIM_Date )

 

If a Date table isn't an option you can try @Greg_Deckler solution

 

The Case for No CALCULATE (linkedin.com)

 

RunningTotal =
VAR __Date = MAX('Table'[Date])
VAR __Table = FILTER(ALLSELECTED('Table'),[Date] <= __Date)
VAR __Result = COUNTX(__Table,[Items])
RETURN
    __Result   

 

Hope this helps

Joe

 

If you found my answer helpful and it solved your issue, please accept as solution 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Learn about the Star Schema, it will solve many issues in Power BI!

Date tables help! Learn more



LinkedIn
Let's connect on LinkedIn


View solution in original post

2 REPLIES 2
Joe_Barry
Super User
Super User

Hi @game1 

 

There are two possibilities. The first one will require a date table as @DAX_Machine  suggested. When the data model is set up correctly you can use the Date from the Date table in the visual and then add this measure

 

RunningTotal =
VAR MaxDate =
    MAX ( DIM_Date[Date] )
RETURN
    CALCULATE (
        COUNTROWS(Table),
        KEEPFILTERS ( 'Table'[Date] <= MaxDate
            && 'Table'[Date] >= MaxDate,
        ALL ( DIM_Date )

 

If a Date table isn't an option you can try @Greg_Deckler solution

 

The Case for No CALCULATE (linkedin.com)

 

RunningTotal =
VAR __Date = MAX('Table'[Date])
VAR __Table = FILTER(ALLSELECTED('Table'),[Date] <= __Date)
VAR __Result = COUNTX(__Table,[Items])
RETURN
    __Result   

 

Hope this helps

Joe

 

If you found my answer helpful and it solved your issue, please accept as solution 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Learn about the Star Schema, it will solve many issues in Power BI!

Date tables help! Learn more



LinkedIn
Let's connect on LinkedIn


DAX_Machine
Frequent Visitor

Good Morning, 
do You have a DateTable ? 
if not you can create one by using this code:

DIM_Datetable =
VAR calender =

CALENDAR(
Date( 2020,01,01 -- FirstDate
),
DATE(
2030,01,01 -- Last Date
)
)

RETURN

ADDCOLUMNS(
calender,
Year,YEAR([Date]),
Quarter, CONCATENATE(Q,QUARTER([Date])),
Year Month, YEAR([Date]) & - & FORMAT(MONTH([Date]), 00),
Month, MONTH([Date]),
Month Name, FORMAT([Date], MMMM),
Day of year, DATEDIFF(DATE(YEAR([Date]),1,1),[Date],DAY)+1,
Day of Month, DAY([Date]),
Day of week, WEEKDAY([Date],2),
Day Name, FORMAT([Date], DDDD),
Weeknum, FORMAT(WEEKNUM([Date],2),00),
Year Weeknum, YEAR([Date]) & FORMAT(WEEKNUM([Date],2),00),
Year Quarter, YEAR([Date]) & - & QUARTER([Date])
)

This code will create a date table including the dates you specify. After creating this table You can connect it with your fact table by a one to many relationship then use the date table instead of your date column in your graph.

Let me know if this was useful!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.