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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
coco6l
Frequent Visitor

Cumulative sum

I have two curves representing the hours planned and completed for each month.
Capture d'écran 2024-02-15 120718.png
I'd like to sum up the hours planned for each year, then calculate this sum and subtract the hours actually worked, to see how the hours consumed have evolved. The difficulty I'm having is that I'm having problems with my data modeling (maybe I need to modify something with my data architecture because I have Sum of Initial No. Hours 2023 and 2024 that I've calculated (I'm also interested in sources on how to properly model data for Power BI). I was able to remedy this by calculating the planned hours for the period :

 

 

 

Heures prévues période = 
VAR DateMin = MIN('Heures réalisées'[Date]) // Recovers the minimum date after filtering
VAR DateMax = MAX('Heures réalisées'[Date]) // Retrieves the maximum date after filtering
VAR NbMois = DATEDIFF(DateMin, DateMax, MONTH) + 1 // Calculates the number of evolved months
RETURN
[Heures Prévues] * NbMois // Multiplies the scheduled hours by the number of months elapsed

 

 

 

I've tried some complex calculations but without success, and I think there's a simpler way of doing this. In addition, I'm interested in the possibility of forcasting the hours achieved by displaying them with dashes, for example forcasting.

Thank you for your help (and sorry for the content in french)

2 REPLIES 2
mh2587
Super User
Super User

//Try this
Difference (Planned - Actual) = 
VAR SumPlannedHours = SUM('Heures prévues'[Heures Prévues])
VAR SumCompletedHours = SUM('Heures réalisées'[Heures Réalisées])
VAR PlannedHoursPerYear = CALCULATE(SumPlannedHours, ALLEXCEPT('Date Table', 'Date Table'[Year]))
VAR CompletedHoursPerYear = CALCULATE(SumCompletedHours, ALLEXCEPT('Date Table', 'Date Table'[Year]))

RETURN
PlannedHoursPerYear - CompletedHoursPerYear

✔ Answered? Mark as solution

Muhammad Hasnain | Super User • Fabric • Power BI • Data Engineering

Let's connect on LinkedIn
coco6l
Frequent Visitor


Hello @mh2587,
Thank you very much for the reply. I wanted to do sth like this exactly, I still have the problem that "heures prévues" is measure style and so I can't sum? Capture d'écran 2024-02-15 153940.png
If ever here is my structure and my measure "heures prévues".

 

Heures prévues = 
VAR YearOfDate = YEAR(MAX('Heures réalisées'[Date])) // ou MIN, selon la granularité de vos données
RETURN
DIVIDE(
    SWITCH(
        YearOfDate,
        2023, SUM('Heures prévues'[Nbre Heures initial 2023]),
        2024, SUM('Heures prévues'[Nbre Heures initial 2024]),
        BLANK()
    ),
    12
)

 


Thanks

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors