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
lemmallari
Regular Visitor

Aggregating values from different tables to another column in a Parent Table

I currently have multiple tables, let's call them PortalData1, PortalData2, PortalData3 and PortalData4. These four tables have the following columns, Hits, Ratings, Date. Mock Data is shown below (let's assume for now that all values in all 4 tables are the same):

 

HitsRatingsDate
1003Date 1
2004Date 2
3005Date 3

 

I created a new table called Portal with columns PortalID and PortalName. I then added columns to the first four tables I created called PortalID to link them with the Portal table I created. So for exmaple, PortalData1 now looks like this:

 

HitsRatingsDatePortalID
1003Date 11
2004Date 21
3005Date 31

 

Portal table looks like this:

 

PortalIDPortalName
1Portal1
2Portal2
3Portal3
4Portal4

 

What I need now is to have a Hits column in my Portal table so that it will show the sum of all hits per Portal. So for example, Portal1 has a total of 100, Portal2 has a total of 200 and son on, I would like my Portal table to look like this:

 

PortalIDPortalNameHits
1Portal1100
2Portal2200
3Portal3300
4Portal4400

 

Is this possbile via PowerBI? How should I approach this? Do I need to create a measure or a calculated column? I'm pretty new to Power BI so any help or suggestion will be appreciated. Thanks!

1 ACCEPTED SOLUTION

@lemmallari

 

Yes, it is possible, you could refer to below code to get total hits.

 Total = SUMX(FILTER(SELECTCOLUMNS(UNION(PortalData1,PortalData2,PortalData3,PortalData4),"ID",[PortalID],"Name",[PortalName],"Hit",[Hits]),[ID]=Portal[PortalID]),[Hit])
Capture.PNG


Reference function:
UNION : Use to merge records.
SELECTCOLUMNS: Rename columns.
SUMX: get the total amount.

 

Regards,

Charlie Liao

View solution in original post

3 REPLIES 3


@lemmallari wrote:
 

Is this possbile via PowerBI? How should I approach this? Do I need to create a measure or a calculated column? I'm pretty new to Power BI so any help or suggestion will be appreciated. Thanks!


 

Yes it is possible. The easiest is to use power query (get data) to append the 4 data tabkes into 1. Alternatively you can link all 4 tables (data tables) to the one lookup table.  Read about multiple data tables here http://exceleratorbi.com.au/multiple-data-tables-power-pivot/



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

Hi! Thanks for your answer, unfortunately I'm still new to Power BI and have no idea how to do the things you mentioned. Would you have a step by step procedure to that? The link you provided from my understanding, assumes that the reader is already familiar with Power BI.

@lemmallari

 

Yes, it is possible, you could refer to below code to get total hits.

 Total = SUMX(FILTER(SELECTCOLUMNS(UNION(PortalData1,PortalData2,PortalData3,PortalData4),"ID",[PortalID],"Name",[PortalName],"Hit",[Hits]),[ID]=Portal[PortalID]),[Hit])
Capture.PNG


Reference function:
UNION : Use to merge records.
SELECTCOLUMNS: Rename columns.
SUMX: get the total amount.

 

Regards,

Charlie Liao

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.