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

Calculating cumulative Months by project code

Hi There,

 

I am trying to calculate a cumulative monthly total (adding each months total to the previous month) and filtered by relevant project codes. I have the following headings which i am using;

 

Project code / Actual Monthly Cost / Date / Month Number

 

I have been trying the use the below formula however it doesnt seem to be working;

 

Cumulative_actual = CALCULATE(DISTINCTCOUNT([Actual Monthly Cost]);FILTER(ALLEXCEPT, SHEET NAME [ProjectCode], SHEET DATE[Month number] <=MAX(SHEET [Month number]

 

If anyone is able to help that would be much appreciated. 

2 ACCEPTED SOLUTIONS

Hi,

 

I have now managed to create the formulas 🙂 Thank you

View solution in original post

 

The below formula seems to work;  I created a sum column calculating figures by month, then created another colum to filter by project;

 

Monthly Sum = CALCULATE(SUM(Financials[Actual Monthly Cost]),FILTER(ALL(Financials),Financials[Date] <=TODAY()))

 

By Project = CALCULATE(SUM(Financials[Actual Monthly Cost]),ALLEXCEPT(Financials,Financials[ProjectCode],Financials[Monthly Sum]))

 

View solution in original post

9 REPLIES 9
TomMartens
Super User
Super User

Hey,

 

thanks for sharing sample data, maybe you might consider to share the link using a normal post and not a private message 🙂

 

Nevertheless ...

 

I created a new column that just contains a date datatype using this statement, because your sample data did not contain a column called "Month Number":

A Date Column = 
DATE('Financials'[Year]
    ,SWITCH('Financials'[Month]
        ,"January",1
        ,"February",2
        ,"March",3
        ,"April",4
        ,"May",5
        ,"June",6
        ,"July",7
        ,"August",8
        ,"September",9
        ,"October",10
        ,"November",11
        ,"December",12)
    
    ,1)

After that I created another calculated column, that acumulates the values from the column Actual Monthly Cost:

**bleep** Actual Monthly Cost = 
var currentDate = 'Financials'[A Date Column]
var currentProjectCode = 'Financials'[ProjectCode]
return 
CALCULATE(
    SUM('Financials'[Actual Monthly Cost])
    ,FILTER(ALL('Financials')
        ,Financials[A Date Column] <= currentDate
        //&& 'Financials'[ProjectCode] = currentProjectCode
    )
)

I was'n sure if you wanted this calculation per Projectcode (probable: inspecting the formula you provided). If this is the case, just remove the comment sign // from this line

//&& 'Financials'[ProjectCode] = currentProjectCode

If you do not need the line, you can remove the following lines:

...
var currentProjectCode = 'Financials'[ProjectCode]
...
        //&& 'Financials'[ProjectCode] = currentProjectCode
...

Here is a little screenshot:

image.png

 

As you can see, there is an issue with the February issues, this will be automatically resolved if the acumulation has to happen for each Projectcode separately. If not the calculation will become much more sophisticated, and can't be achieved using a calculated column. And you also have to provide an explanation about the nature of your sample data and provide the expected result that matches your sample data.

 

Regards

Tom

 

 

 

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Many thanks for your response. I have managed to calculate a monthly sum of the Actual Monthly Cost now however, still unable to filter the Actual Monthly cost by project code (so currently it is showing the figure as a sum of all projects). I am unable to get the last part of the formula to work; //&& 'Financials'[ProjectCode] = currentProjectCode

 

 

@Bryony,

Could you please share sample data of your table and expected result through online service such as OneDrive?

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi,

 

I have now managed to create the formulas 🙂 Thank you

Hey @Bryony,

 

this is a great!

 

Can you please post your solution and mark it as answer, this will help all the other community members (including me) a lot!!

 

Thanks

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

 

The below formula seems to work;  I created a sum column calculating figures by month, then created another colum to filter by project;

 

Monthly Sum = CALCULATE(SUM(Financials[Actual Monthly Cost]),FILTER(ALL(Financials),Financials[Date] <=TODAY()))

 

By Project = CALCULATE(SUM(Financials[Actual Monthly Cost]),ALLEXCEPT(Financials,Financials[ProjectCode],Financials[Monthly Sum]))

 

v-yuezhe-msft
Employee
Employee

@Bryony,

Please check if one of the following DAX returns your expected result.

Cumulative_actual = CALCULATE(DISTINCTCOUNT([Actual Monthly Cost]);FILTER(ALLEXCEPT(SHEETNAME;SHEET NAME [ProjectCode]); SHEET DATE[Month number] <=MAX(SHEET [Month number])))
Cumulative_actual = CALCULATE(DISTINCTCOUNT([Actual Monthly Cost]),FILTER(ALLEXCEPT(SHEETNAME,SHEET NAME [ProjectCode]),SHEET DATE[Month number] <=MAX(SHEET [Month number])))



Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
TomMartens
Super User
Super User

Hey,

 

as far as I can see the formula you provided will not work due to missing parnetheses.

 

I would recommend that you create some sample data, upload the pbix to onedrive or dropbox and share the link.

 

Regards

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Many thanks Tom. I have just sent the link to your inbox. 

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.