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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
game1
Helper II
Helper II

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
Solution Specialist
Solution Specialist

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 

View solution in original post

2 REPLIES 2
Joe_Barry
Solution Specialist
Solution Specialist

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 

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.