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
Rickstor
Frequent Visitor

cumulative days using DAX - Why is it so easy in Excel but not in DAX?

Hi. 

Please help me with this task: 

I need to create a cumulative days (measure) and days between (measure). I need these measures to use them in a table visual.
Like this:

Rickstor_0-1691521923764.png

 

'cum_days' is the name of measure. 

'days_between' is another measure that I need. 

In this model, I have a date table with relationship with my principal table. 

In Excel is so easy to do. 

But in DAX I have tried so many ways and I can't. 

 

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @Rickstor 

 

You can try the following methods.
Measure:

days_between =
DATEDIFF (
    MAXX ( FILTER ( ALL ( 'Table' ), [Date] < SELECTEDVALUE ( 'Table'[Date] ) ), [Date] ),
    SELECTEDVALUE ( 'Table'[Date] ),
    DAY
)
cum_days = SUMX(FILTER(ALL('Table'),[Date]<=SELECTEDVALUE('Table'[Date])),[days_between])

vzhangti_0-1691736191779.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

3 REPLIES 3
v-zhangti
Community Support
Community Support

Hi, @Rickstor 

 

You can try the following methods.
Measure:

days_between =
DATEDIFF (
    MAXX ( FILTER ( ALL ( 'Table' ), [Date] < SELECTEDVALUE ( 'Table'[Date] ) ), [Date] ),
    SELECTEDVALUE ( 'Table'[Date] ),
    DAY
)
cum_days = SUMX(FILTER(ALL('Table'),[Date]<=SELECTEDVALUE('Table'[Date])),[days_between])

vzhangti_0-1691736191779.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Mahesh0016
Super User
Super User

@Rickstor 
Running Total MEASURE =

 CALCULATE(
     [Total Sales],
     FILTER(
            ALLSELECTED(financials[Date]),
            financials[Date]<=MAX(financials[Date])
     )
 )


ELSE
Running Total MEASURE =
CALCULATE ( [Total Sales], Date[Date] <= MAX ( Date[Date] ) )

 

 

johnt75
Super User
Super User

You could create measures like

Cumulative days =
VAR MinDate =
    CALCULATE ( MIN ( 'Table'[Date] ), ALLSELECTED ( 'Table' ) )
VAR CurrentDate =
    SELECTEDVALUE ( 'Table'[Date] )
VAR Result =
    DATEDIFF ( MinDate, CurrentDate, DAY )
RETURN
    Result

Days between =
VAR CurrentDate =
    SELECTEDVALUE ( 'Table'[Date] )
VAR Dates =
    ALLSELECTED ( 'Table'[Date] )
VAR PrevDate =
    OFFSET ( -1, Dates, ORDERBY ( 'Table'[Date], DESC ) )
VAR Result =
    DATEDIFF ( PrevDate, CurrentDate, DAY )
RETURN
    Result

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.