cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
brunoemr
Frequent Visitor

Dax to a cumulative sum

Hi All,

 

I'm struggling here...

 

I'm trying to do a chart with a cumulative sum of hours reported during the contracts period for each contract.

 

Reported Hours are in Timeworked table and the contract period are in TblContracts, fields TblContracts[Contract Start Date] and TblContracts[Contract End Date] don't have any relations.

 

 

My data model:

brunoemr_1-1612348700362.png

 

 

brunoemr_0-1612348687627.png

I'm using the Dax below, it returns the reported hours on the period, but it does not return the cumulative values.

 

 

Cumulative TimeWorked =
var starts_ = MAX(TblContracts[Contract Start Date])
var ends = MAX(TblContracts[Contract End Date])
return
CALCULATE(
SUM(Timeworked[Total_time_in_hours])
,FILTER( Date_dim,
Date_dim[full_date] >= starts_ &&
Date_dim[full_date] <= ends
)
,CROSSFILTER (Timeworked[date_dim_id],Date_dim[date_dim_id], BOTH )
,CROSSFILTER ( Timeworked[task_dim_id], Overview[project_task_dim_id], BOTH)
)

 

 

 

How can I achieve the cumulative values?

 

Thanks in advance.

BrunoR.

1 ACCEPTED SOLUTION
brunoemr
Frequent Visitor

Hi,

 

Have found a solution.

 

Final Dax:

 

 

Cumulative TimeWorked = 
VAR minDate =
    MIN ( TblContracts[Contract Start Date] )
VAR maxDate =
    MAX ( TblContracts[Contract End Date] )
VAR totalHours =
    CALCULATE (
        SUM ( Timeworked[Total_time_in_hours] ),
        FILTER (
                ALL ( Date_dim ),
                Date_dim[date] >= minDate
                && Date_dim[date] <= MAX ( Date_dim[date] )
                && ( MAX ( Date_dim[date] ) <= TODAY() && MAX ( Date_dim[date] ) <= maxDate)
        )
        ,   CROSSFILTER ( TblContracts[SNOW reporting ticket - billable ], Overview[project_task_number], BOTH )
        ,   CROSSFILTER ( Timeworked[task_dim_id], Overview[project_task_dim_id], Both)            
        ,   CROSSFILTER ( Timeworked[date_dim_id], Date_dim[date_dim_id], BOTH )
    )

return totalHours

 

 

 

Thanks,

Bruno

View solution in original post

3 REPLIES 3
brunoemr
Frequent Visitor

Hi,

 

Have found a solution.

 

Final Dax:

 

 

Cumulative TimeWorked = 
VAR minDate =
    MIN ( TblContracts[Contract Start Date] )
VAR maxDate =
    MAX ( TblContracts[Contract End Date] )
VAR totalHours =
    CALCULATE (
        SUM ( Timeworked[Total_time_in_hours] ),
        FILTER (
                ALL ( Date_dim ),
                Date_dim[date] >= minDate
                && Date_dim[date] <= MAX ( Date_dim[date] )
                && ( MAX ( Date_dim[date] ) <= TODAY() && MAX ( Date_dim[date] ) <= maxDate)
        )
        ,   CROSSFILTER ( TblContracts[SNOW reporting ticket - billable ], Overview[project_task_number], BOTH )
        ,   CROSSFILTER ( Timeworked[task_dim_id], Overview[project_task_dim_id], Both)            
        ,   CROSSFILTER ( Timeworked[date_dim_id], Date_dim[date_dim_id], BOTH )
    )

return totalHours

 

 

 

Thanks,

Bruno

View solution in original post

amitchandak
Super User
Super User

@brunoemr , Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

refer if this blog can help

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

For sure, here it is a sample:

 

brunoemr_0-1612357457730.png

brunoemr_1-1612357475832.png

 

brunoemr_0-1612361768605.png

 

My Datedim have all dates from 2013 to 2030, I need to avoid future dates.

 

Thanks

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

November Power BI Update 768x460.png

Check it Out!

Click here to read more about the November 2021 Updates!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.