How to get data from 2 columns, in different tables within Power Query, to sum into 1 column? - excel-formula

How to get data from 2 columns, in different tables within Excel Power Query, to sum into 1 column?
For example: Table names - Main_Company_HR_Data and Company1_HR_Data -- Fields I want to combine: Main_Company_HR_Data.Gross Company1_HR_Data.Gross.
Within the Data Model; I have established the connection to my data warehouse, and have linked the tables in Power Query as well. I added a column and attempted several suggestions from multiple sites. None work. I have been using: Calculate(SUMX(Main_Company_HR_Data.Gross))+ SUMX(Company1_HR_Data.Gross). And other iterations of the sort, and it doesn't work.

I had this issue, and the way I tackle it, is to make it as simple as possible.
Try this:
Enter this code as a formula, adding a column, in the tab which will have the field summed.
=LOOKUPVALUE('Company1_HR_Data'[Gross],'Company1_HR_Data'[Unique_ID],'Main_Company_HR_Data'[Unique_ID])
Create a column to sum the two in the same tab you created the above formula.
='Main_Company_HR_Data'[Gross]+'Company1_HR Data'[Gross]

Related

Excel query join tables

I have 4 tables reporting monthly sales of a product line; each table displays sales from a sdepcific channel (B2B, Ecommerce, Monobrand, Customized) and I'd like to stack these 4 tables one after the other.
Each table has the same exact columns, I can't do copy and paste because I need to update the 4 tables monthly.
I've tried to create a unique database and gather the information from the system throug a sequence of IF, IFS and SUMIFS but even though I get to the result, this takes forever in calculation
Is there a way to do it? I don't know, maybe with Powerquery or creating a Power Pivot?
Thank you
Load the tables into Power Query and append them in the Combine section of the Home tab.

How to use the unique items from in a column from several tables as the row criteria of a pivot table in excel data model using Dax?

I have 3 different tables with the customer name and there are duplicates as well as unique customers in the 3 tables and I need to get the unique for all 3 to be used as the rows criteria in the pivot table.
I've been finding a way to do so but I cannot seem to figure it out.
The measure I tried is: Customers:=DISTINCT(UNION(VALUES('Test1 - Invoice'[CustomerID]),VALUES('Test2 - Invoice'[CustomerID]),VALUES('Test3 - Invoice'[CustomerID])))
But I get the error below:
Semantic Error: Too many arguments were passed to the VALUES function.
The maximum argument count for the function is 1.
I am quite new to DAX and have no idea how to do it. I believe it is because measures are only for values if i'm not mistaken
I read that to place on other fields of the pivot table, it has to be a calculated column although I do not see how it can be a calculated column as well.
One approach is to create a separate table to store the Customer Name dimension - then create relationships between that Customer dimension table and your 3 fact tables. This would be most effective at the Power Query stage, but can be done using DAX.
An alternative is to merge your 3 fact tables - again, this would be best done with Power Query, but is possible with DAX.

Missing rows when merging

I am working with Excel 2010, Power Query, and PowerPivot.
I have a query named Database that consists of 60+ merged tables containing a total of 2m+ rows. I also have a separate query that consists of two columns PrimaryKey3 and Members (a count of members per month). The entries in PrimaryKey3 are unique, consisting of ID-MMM-YY.
Both queries have PrimaryKey3 in common, however in Database there can be multiple rows with the same PrimaryKey3.
In order to match a member amount to each row in Database, I tried a Left Outer join. There were no errors, but when I try to upload to PowerPivot it says there are only 169K rows. I then tried Full Outer join and Inner Join, and received an error "could not convert value to number," coming from a column already formatted as a text in Database. This column contains numbers and numbers proceeding with a letter: 1234, A234. Every non-blank row has a PrimaryKey3. Why is it trying to reformat my columns/ how do I get around that?
Should I be using a different type of join, or is there another way besides merging to do this?
Hope this makes sense, thank you for any help in advance!
I uploaded both queries to PowerPivot, and created a relationship through PrimaryKey3. I then created a new column in Database with =Related(Enrollment[Members]).

Avoid DISTINCTCOUNT in PowerPivot

Due to performance issues I need to remove a few distinct counts on my DAX. However, I have a particular scenario and I can't figure out how to do it.
As example, let's say one or more restaurants can be hired at one or more feasts and prepare one or more menus (see data below).
I want a PowerPivot table that shows in how many feasts each restaurant was present (see table below). I achieved this by using distinctcount.
Why not precalculating this on Power Query? The real data I have is a bit more complex (more ID columns) and in order to be able to pivot the data I would have to calculate thousands of possible combinations.
I tried adding to my model a Feast dimensional table (on the example this would only be 1 column of 2 rows). I was hoping to use that relationship to be able to make a straight count, but I haven't been able to come up with the right DAX to do so.
You could use COUNTROWS() combined with VALUES().
Specifically, COUNTROWS() will give you the count of rows in a table. That means COUNTROWS is expecting a table is input. Here's the magic part: VALUES() will return a table as results, and the table it returns are the distinct values in the table/column that you provide as the argument for VALUES().
I'm not sure if I'm explaining it well, so for the sample data you provided, the measure would look like this (assuming the table is named Table1):
Unique Feasts:=COUNTROWS(VALUES('Table1'[Feast Id]))
You can then create a pivot table from Powerpivot, and drag Restaurant Id into Rows, and drag the measure above into Values. Same result as DISTINCTCOUNT, but with less performance overhead (I think).

How to calculate number of rows in a 1-to-many relationship in PowerPivot

I'm trying to do what I thought was a relatively simple calculation between 2 tables I have in the new PowerPivot add-on for Excel 2010.
My 2 tables loaded at setup as follows:
Table 1:
FooID, BarID, Name
Table 2:
BarID, Date
There is a 1 to many relationship between Table 1 and 2.
I want to add a calculated column to Table 1 that just does a sum of all the rows in Table 2.
I've tried this with no luck. The calculation results in null in every column. Excel isn't reporting an error, so it's not that the calculation is invalid, it's just doing somethign I"m not understanding.
=CALCULATE(COUNTROWS(Table2), Filter(Table2, Table2[BARID] = Table1[BARID]))
I also tried something simpler that I thought would also work:
=COUNTROWS(RELATEDTABLE(Table2))
However that also results in null.
I have made sure that table 1 and table 2 have a relationship on BARID.
=COUNTROWS(RELATEDTABLE(Table2)) is the correct formula if there is an existing relationship.
Might it be that there simply are no matching keys?
You can try that by using your first formula and matching an explicit value eg.:
=CALCULATE(COUNTROWS(Table2), Filter(Table2, Table2[BARID] = "SomeBARIDFromTable2"))
The above formula works on tables regardless of wheter a relationship is defined.
HTH,
Hrvoje

Resources