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

Create totals table from multiple tables

 

 

Hi

 

I hope someone can help. I have two tables [display] and [sem] and a [country] table. I'd like to cerate a TOTAL TABLE that has the fields Country, Total Active Visits (DISP +SEM active visits), Total Clicks, (DISP +SEM clicks) Total Impressions etc (the highlighted in yellow fields) and wondered if this is possible using DAX or should I do it in the source data in Excel?

 

The expected result would be a new table like this:

 

Country, Total Active Visits, Total Clicks, Total Impressions

 

I've tried SUMMARIZE but that only works on one table, I've tried a merge query but that doesn't help.

 

Any help would be welcome!

 

Thanks

 

Jonathan

 

pbi - sem.PNGpbi - display.PNGpbi - countries.PNGpbi - fields.PNG

 

 

1 ACCEPTED SOLUTION
jonathanlyon
Regular Visitor

 

Huge thanks to Phillip Seamark who came up with an awesome solution whilst waiting to board a plane:-

 

Totals = 

Var MyVisits = SUMMARIZECOLUMNS(
                    sem[Country SEM],
                    "Total Active Visits SEM",SUM('sem'[Active Visits SEM]),
                    "Total Clicks SEM" , SUM('sem'[Clicks SEM]),
					"Total Referrals SEM" , SUM('sem'[Referrals SEM]),
					"Total Spend SEM" , SUM('sem'[Spend])
                    )
var myDisplay = SUMMARIZECOLUMNS(
                    'display'[Country DISP],
                    "Total Impressions",SUM('display'[Impressions]),
					"Total Active Visits DISP",SUM('display'[Active Visits DISP]),
					"Total Clicks DISP" , SUM('display'[Clicks DISP]),
					"Total Referrals DISP" , SUM('display'[Referrals DISP]),
					"Total Spend DISP" , SUM('display'[Spend])
                    )      
        
var FirstTable = NATURALLEFTOUTERJOIN(
            SELECTCOLUMNS(countries,"Country",[country] & ""),
            SELECTCOLUMNS(myDisplay,"Country",[Country DISP] & "" , 
                "Total Impressions" ,[Total Impressions] & "" , 
				"Total Clicks DISP" ,[Total Clicks DISP]& "" , 
				"Total Referrals DISP" ,[Total Referrals DISP]& "" ,
				"Total Active Visits DISP" ,[Total Active Visits DISP]& "" , 
				"Total Spend DISP" ,[Total Spend DISP]
            )
            )
            
            
var FinalTable = NATURALLEFTOUTERJOIN(
            FirstTable,
            SELECTCOLUMNS(
                MyVisits,
                "Country",[Country SEM] & "",
                "Total Active Visits SEM",[Total Active Visits SEM],
				"Total Referrals SEM",[Total Referrals SEM],
				"Total Spend SEM",[Total Spend SEM],
                "Total Clicks SEM" , [Total Clicks SEM]))            
return FinalTable

View solution in original post

3 REPLIES 3
jonathanlyon
Regular Visitor

 

Huge thanks to Phillip Seamark who came up with an awesome solution whilst waiting to board a plane:-

 

Totals = 

Var MyVisits = SUMMARIZECOLUMNS(
                    sem[Country SEM],
                    "Total Active Visits SEM",SUM('sem'[Active Visits SEM]),
                    "Total Clicks SEM" , SUM('sem'[Clicks SEM]),
					"Total Referrals SEM" , SUM('sem'[Referrals SEM]),
					"Total Spend SEM" , SUM('sem'[Spend])
                    )
var myDisplay = SUMMARIZECOLUMNS(
                    'display'[Country DISP],
                    "Total Impressions",SUM('display'[Impressions]),
					"Total Active Visits DISP",SUM('display'[Active Visits DISP]),
					"Total Clicks DISP" , SUM('display'[Clicks DISP]),
					"Total Referrals DISP" , SUM('display'[Referrals DISP]),
					"Total Spend DISP" , SUM('display'[Spend])
                    )      
        
var FirstTable = NATURALLEFTOUTERJOIN(
            SELECTCOLUMNS(countries,"Country",[country] & ""),
            SELECTCOLUMNS(myDisplay,"Country",[Country DISP] & "" , 
                "Total Impressions" ,[Total Impressions] & "" , 
				"Total Clicks DISP" ,[Total Clicks DISP]& "" , 
				"Total Referrals DISP" ,[Total Referrals DISP]& "" ,
				"Total Active Visits DISP" ,[Total Active Visits DISP]& "" , 
				"Total Spend DISP" ,[Total Spend DISP]
            )
            )
            
            
var FinalTable = NATURALLEFTOUTERJOIN(
            FirstTable,
            SELECTCOLUMNS(
                MyVisits,
                "Country",[Country SEM] & "",
                "Total Active Visits SEM",[Total Active Visits SEM],
				"Total Referrals SEM",[Total Referrals SEM],
				"Total Spend SEM",[Total Spend SEM],
                "Total Clicks SEM" , [Total Clicks SEM]))            
return FinalTable
v-caliao-msft
Employee
Employee

@jonathanlyon,

 

In DAX expression, SUMMARIZE function accept only one table for the first parmater.  So in your scenario, you could create a summarize cournty table, and then add columns to this table by using REMATED or LOOKUPVALUE function.

RELATED function returns a related value from another table.
https://msdn.microsoft.com/en-us/library/ee634202.aspx
Lookupvalue function returns the value in result_columnName for the row that meets all criteria specified by search_columnName and search_value.
https://msdn.microsoft.com/en-us/library/gg492170.aspx

 

If this is not what you want, please provide us some sample data, so that we can try to give you a more detail solution.

 

Regards,

Charlie Liao

GilbertQ
Super User
Super User

Hi @jonathanlyon

 

What I would suggest doing is to Append the tables in the Query Editor

 

What this will do is to then Append them together. When the column names are the same it will append the data into the same columns.

And when the columns are different after appending they will then go into a new column with the existing name. (And where there ae no values, it will just be shown as null)

 

So when you now load the data you will then have all your data in one table.

 

You can then get the information you need from this one table, which will also include your Country names.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

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.