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
Anonymous
Not applicable

How to create a calculated column that aggregates line by line using a filter

Hi, I would like to create a separate table based on an existing table that aggregates client revenue by year.  However, I can't seem to get a formula to aggregate the revenues by client.  


For example, 

 

The main Table contains the following information:

 

Main Data Table example.png

 

I created another table that summarizes all the client names from the Main Data Table

Table 2:

Client Name:

Client A

Client B

Client C

 

Then, I need to calculate the sum of the revenue for each client by year.   

Table 2 Example.png

 

I have tried the following formula: = Calculate(sum(MainDataTable[Revenue]),filter(MainDataTable, MainDataTable[Year]=2017)

The results ended up to be the total revenue for 2017 repeated for each client. 

Client Name     2017 Revenue

Client A                     135

Client B                     135

Client C                     135

 

I have also tried to add the client name to the filter: =Calculate(sum(MainDataTable[Revenue]),filter(MainDataTable, MainDataTable[Year]=2017 && MainDataTable[Client Name])

 

However I get an error message 

 

Any help would be much appreciated.

 

 

1 ACCEPTED SOLUTION

Hi,

 

Try these calculated column formulas in the Client sheet

 

=CALCULATE(SUM(MainDataTable[Revenue]),FILTER(MainDataTable,MainDataTable[Client Name]=EARLIER([Client Name])&&MainDataTable[Year]=2017))

 

=CALCULATE(SUM(MainDataTable[Revenue]),FILTER(MainDataTable,MainDataTable[Client Name]=EARLIER([Client Name])&&MainDataTable[Year]=2018))

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

 

Try this

 

  1. Create a relatiosnhip from Table 2 to Table 1 on the Client Name column
  2. In your Matrix visual, drag the Client Name column from Table 2 to the row labels and year to the column labels
  3. Write this measure

=SUM(MainDataTable[Revenue])

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Thank You for the response. However, I visual isn't the solution I'm looking for.  I need to create the separate table 2 because I will be building onto it.  So usuing a calculated column is the best solution for me at the moment. Any other possible suggestions?

Hi,

 

Try these calculated column formulas in the Client sheet

 

=CALCULATE(SUM(MainDataTable[Revenue]),FILTER(MainDataTable,MainDataTable[Client Name]=EARLIER([Client Name])&&MainDataTable[Year]=2017))

 

=CALCULATE(SUM(MainDataTable[Revenue]),FILTER(MainDataTable,MainDataTable[Client Name]=EARLIER([Client Name])&&MainDataTable[Year]=2018))

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Thank You! This worked perfectly.  Just for my understanding, can you explain why using EARLIER in the formula made it work?

 

You are welcome.  In simple language, EARLIER() can be substituted with CURRENTROW().


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Thank you! great to know.

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.