cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate II
Advocate II

Calculated Column of Sum per Month

Hello!

 

I have a calculation to complete that requires a sum of the current month. Note, I need this to be done with a calculated DAX column, not a measure unfortunately! My calculation is pretty advanced and will be easier if i had this column.

 

To explain more clearly what I am looking for my desired output is shown below as TotalPerMonth:

 

Sales  
DateAmountTotalPerMonth
7/1/2018534
7/1/2018634
7/1/2018734
7/2/2018234
7/2/2018334
7/2/2018334
7/3/2018434
7/3/2018334
7/3/2018134
8/1/2018239
8/1/2018339
8/1/2018339
8/2/2018239
8/2/2018339
8/2/2018539
8/3/2018639
8/3/2018739
8/3/2018839

 

The above table is should portray most of my caveats of my data, however, attached in the spoiler tag is a more rigororus dataset:

 

 

Spoiler
DateAmountTotalPerMonth
5/31/2018 0:0053869.971259637
5/31/2018 1:0054058.041259637
5/31/2018 2:0053270.371259637
5/31/2018 3:0054487.841259637
5/31/2018 4:0054003.491259637
5/31/2018 5:0052144.591259637
5/31/2018 6:0047906.151259637
5/31/2018 7:0049621.781259637
5/31/2018 8:0054271.141259637
5/31/2018 9:0053384.481259637
5/31/2018 10:0050849.781259637
5/31/2018 11:0053899.411259637
5/31/2018 12:0054124.261259637
5/31/2018 13:0053406.911259637
5/31/2018 14:0048970.371259637
5/31/2018 15:0048303.021259637
5/31/2018 16:0052115.21259637
5/31/2018 17:0053370.161259637
5/31/2018 18:0051550.341259637
5/31/2018 19:0051057.451259637
5/31/2018 20:0052635.511259637
5/31/2018 21:0053951.191259637
5/31/2018 22:0054479.151259637
5/31/2018 23:0053906.861259637
6/1/2018 0:0052760.431234373
6/1/2018 1:0052897.11234373
6/1/2018 2:0050640.631234373
6/1/2018 3:0052362.221234373
6/1/2018 4:0051984.251234373
6/1/2018 5:0051791.61234373
6/1/2018 6:0048052.681234373
6/1/2018 7:0049226.491234373
6/1/2018 8:0053700.41234373
6/1/2018 9:0053024.821234373
6/1/2018 10:0052481.091234373
6/1/2018 11:0053542.611234373
6/1/2018 12:0052460.781234373
6/1/2018 13:0052598.761234373
6/1/2018 14:0052573.911234373
6/1/2018 15:0052284.611234373
6/1/2018 16:0052712.141234373
6/1/2018 17:0047793.631234373
6/1/2018 18:0046917.881234373
6/1/2018 19:0048769.641234373
6/1/2018 20:0051219.081234373
6/1/2018 21:0053080.731234373
6/1/2018 22:0050553.361234373
6/1/2018 23:0050944.621234373

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Resolver I
Resolver I

Re: Calculated Column of Sum per Month

@coreyweiss

Try this calculated column:

 

TotalPerMonth = CALCULATE(SUM(Table1[Amount]),FILTER(Table1,Table1[Date] = EARLIER(Table1[Date])))

View solution in original post

7 REPLIES 7
Highlighted
Resolver I
Resolver I

Re: Calculated Column of Sum per Month

@coreyweiss

Try this calculated column:

 

TotalPerMonth = CALCULATE(SUM(Table1[Amount]),FILTER(Table1,Table1[Date] = EARLIER(Table1[Date])))

View solution in original post

Highlighted
Advocate II
Advocate II

Re: Calculated Column of Sum per Month

Hey @danb!

 

The code you posted creates an error "EARLIER/EARLIEST refers to an earlier row context which doesn't exist."

 

Any Ideas?

Highlighted
Resolver I
Resolver I

Re: Calculated Column of Sum per Month

@coreyweiss

Enter in the formula as a "New Column" and not a "New Measure"

Highlighted
Advocate II
Advocate II

Re: Calculated Column of Sum per Month

44.PNG

 

Yup, I am entering it as a new column

Highlighted
Resolver I
Resolver I

Re: Calculated Column of Sum per Month

@coreyweiss - it appears that you have some type of error occuring after the "earlier" function. Please see my screenshot below. I have the same column in with the May/June data and it is not tripping the error. 

 

Screenshot_1.png

Highlighted
Advocate II
Advocate II

Re: Calculated Column of Sum per Month

Yes today is a monday, I was adding it as a measure. Smiley Frustrated

 

Your function works, thank you

 

I had to adjust it a bit however: 

 

I made a new column format(table1[date] , "yyyymm")

 

then filtered using that new column.

 

By filtering by date, it gives the sum/ per day instead of per month. big thanks though!

Highlighted
Frequent Visitor

Re: Calculated Column of Sum per Month

Hello @danb ,

 

I am trying to accomplish the same thing, however, I do not have an import file, and therefore, cannot create that in power query...or use the EARLIER function as it is not supported for DirectQuery.

 

Do you have any ideas of how to achieve this?

 

Thanks!

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors