Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Sum per Month per Location

Hello fellow forum friends,

 

I am a noob at DAX and PowerBI and I'm trying to solve the following problem:

 

Table1 has the following columns: Date, Total, and Location.

 

I have many entries per day and location.

 

I want to add an extra column called 'Total per month per location', that would add an entry with the sum of the values in Total for that month on that location.

 

Would look like this:

 

TotalDateLocationTotalPerMonthPerLocation
1501-01-18A25
1002-01-18A25
501-01-18B15
1002-01-18B15
1501-02-18A20
502-02-18A20
2001-02-18B35
1502-02-18B35

 

Right now I managed to have a column that shows the sum of Total on that month, but I also want it to discriminate it via Location.

 

Right now I have this:

 

TotalDateLocationTotalPerMonthPerLocation
1501-01-18A40
1002-01-18A40
501-01-18B40
1002-01-18B40
1501-02-18A55
502-02-18A55
2001-02-18B55
1502-02-18B55

 

My current query is

 

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

 

 

Can anyone help me alter the query so I can achieve what I'm trying to do?

 

Thank you <3

  • Anonymous  Please try this as a new column

     

    TotalPerMonthPerLocation = CALCULATE(SUM(Test192LkpSum[Total]),FILTER(Test192LkpSum, MONTH(Test192LkpSum[Date]) = MONTH(EARLIER(Test192LkpSum[Date])) && Test192LkpSum[Location] = EARLIER(Test192LkpSum[Location])))

2 Replies

  • PattemManohar's avatar
    PattemManohar
    Icon for Community Champion rankCommunity Champion

    Anonymous  Please try this as a new column

     

    TotalPerMonthPerLocation = CALCULATE(SUM(Test192LkpSum[Total]),FILTER(Test192LkpSum, MONTH(Test192LkpSum[Date]) = MONTH(EARLIER(Test192LkpSum[Date])) && Test192LkpSum[Location] = EARLIER(Test192LkpSum[Location])))

    • Anonymous's avatar
      Anonymous
      Not applicable

      PattemManohar 

       

      That worked!

       

      Thank you a lot for your help!