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

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...

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
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.