Newbie with DAX, trying to do something which I thought would be very simple but already hitting a bit of a wall and would appreciate any assistance.
I have table 'General' with columns:
'name', 'age', 'dob', 'address', 'home number', 'state'.
I have table 'Work' with columns:
'name','work address', 'company', 'mobile', 'email'.
I want to create a new (virtual?) table made of the following columns:
'General'[name], 'General'[age], 'General'[state], 'Work'[company], 'Work'[email]
Googling around, some of the solutions for creating a new table look really messy.. isn't there a super simple way to construct this? Thanks!
There are two option, first your can use "Merge Queries" option in the "Power Query Editor". You can merge two or more table this way based on Key column available in both tables. You can also use more than one Key columns for joining purpose. You can add new columns to your left table Or, you can create a new table from those two tables which is my preference. For more details, you can check this below link-
https://radacad.com/how-to-change-joining-types-in-power-bi-and-power-query#:~:text=In%20Power%20BI%20Desktop%20you,Right%20part%20of%20the%20join).
Option 2 is to create two custom columns 'Work'[company] & 'Work'[email] in the table "General". To generate value in those columns, you can use LOOKUPVALUE. Here is a sample code for that -
company =
LOOKUPVALUE(
'Work'[company]
'Work'[id], 'General'[id]
-- Guess you have common ID column in both table for joining
)
Related
In Power BI, I need to create a VLOOKUP alternative. From the research I've done, this is done with the LOOKUPVALUE function, but the problem is that function needs one specific SEARCH ITEM, which isn't super helpful in a VLOOKUP type scenario where you have a full column of values to search for?
Given these two tables, connected through the user_name and first_name columns:
...what's the formula needed in order to create a new column in the Employee_Table called phone_call_group by using the names as the search items in order to return the group they belong to? So how can I end up with this?
(Forget that the entries in each table are already sorted, needs to be dynamic). Will be back tomorrow to review solutions.
In Power BI you have relations between tables instead of Excel's VLOOKUP function.
In your case you just have to create a one-to-one relation between
'Phone_Call_Table'[user_name] and 'Employee_Table'['first_name]'
With that you can add a Calculated Column to your 'Employee_Table' using the following expression:
phone_call_group = RELATED(Phone_Call_Table[group])
and in the data view the table will look like this:
LOOKUPVALUE() is just a workaround if for other reasons you can't establish that relation. What you've been missing so far is that in a Calculated Column there is a Row Context which gives you exactly one value per row for the <search_value> (this is different from Measures):
alt_phone_call_group =
LOOKUPVALUE(
Phone_Call_Table[group],
Phone_Call_Table[user_name],
Employee_Table[first_name]
)
I am currently using the Power BI Power Query Editor writing queries using the Power Query M formula language. I currently have two tables named employee and business. Each row of the employee table has a business_id that connects to a row of the business table. I want to run a Table.SelectRows function to include only the rows where employee.business_id = business.id.
This is what I have so far:
let
Source = MySQL.Database(<DATABASE>, "business_database", [ReturnSingleDatabase=true, CreateNavigationProperties=false]),
business_database_employee_all = Source{[Schema="business_database",Item="employee"]}[Data],
employee_included = . . . Return all rows from employee where employee.business_id = business.id . . .
in
employee_included
Any sort of help with this one would be appreciated! I'm pretty set on using Table.SelectRows but I'm down to utilize better functions if it's recommended!
It sounds like you want to filter the employee table so that it only shows rows where there is a match in the business_id field to the business table
the best way is to merge the business table into the employee table, matching the business_id field, with inner join
#"Merged Queries" = Table.NestedJoin(#"PriorStepNameinEmployeeTable",{"business_id"},business,{"business_id"},"business",JoinKind.Inner)
another way
#"Select" = Table.SelectRows(#"PriorStepNameinEmployeeTable", each Table.Contains(business_table,_,{"business_id"}))
I have what I believe is a simple problem in Power BI, but I'm having trouble solving it.
I have a model with three tables, tbCalendar, tbFiles and tbCategory.
Both the tbCalendar and tbCategory tables have a relationship with tbFiles. tbCalendar's relationship with tbFiles is a many-to-many relationship in a column they both have called "Date" and between tbCategory and tbFiles is a one-to-many relationship made through a column called "Category".
I want to create a measure that makes a distinct count of a column called "KeyCod" of tbFiles where some values are repeated. But I want this measure to ignore all the filters I created except one, the "Date" column filter of tbCategory table to reuse this result in other solutions in my model.
So far I've tried in a few ways, but I haven't gotten the result I need. Could someone help me with this please?
My current measure is:
CountKeyCodRows =
VAR TotalRows = DISTINCTCOUNT(tbFiles[KeyCod])
RETURN CALCULATE(TotalRows,ALLSELECTED(tbCalendar))
Replace ALLSELECTED with ALLEXCEPT
CountKeyCodRows =
VAR TotalRows = DISTINCTCOUNT(tbFiles[KeyCod])
RETURN CALCULATE(TotalRows,ALLEXCEPT(tbCalendar))
I have three different tables. I want to select different columns from each of the tables and create one table based on some filters. Have a look at the following dax expression:
FILTER(DISTINCT(SELECTCOLUMNS(Test_Table,"site_key",[site_key],"is_active",[is_active])),[is_active]=TRUE&&[dbsource]=="DB2")
As you can see, I've selected olumns from Test_Table.
Firstly, How can I add columns from the other two tables?
Secondly, please note that these tables are related so I've created a relationship between them based on relevant IDs.
Will I have to create a natural join in DAX as well?
As I mentioned in the comment, SUMMARIZECOLUMNS can probably get you what you're looking for. It might look something like this in your case:
SUMMARIZECOLUMNS (
Test_Table[site_key],
Test_Table_2[industry_group],
Test_Table_2[country],
Test_Table_2[state],
FILTER ( Test_Table, [is_active] = TRUE && [dbsource] = "DB2" )
)
I have 40 tables. One table has 20 rows, and one of the columns have 1385 distinct values.
I would like to use this in a relationship with another table.
TableName(1385 rows) Column:Name:(1385 distinct values)
But when I try to do this in Powerbi/Manage-Relations, it will only accept the option "Many-to-Many" relationship. It reports that none of the column are "Unique".
Well, the data in the column is unique. So how can I configure this column to be unique so I can use it in a "One-to-Many" relationship"?
Do I have to edit the DAX expression and put the "DISTINCT" keyword in the expression for that column? And How?
Now I have:
}, {"Columnname", Int64.Type}, {
what you can try is to perform remove duplicates in that table(i know its already contains distinct values but you can give it a try)... and/or just load the data again.
Best way would be when you group your data in the query editor. This way your table has only distinct values and you can create your relationship.
In the query designer under Home > Group By you can group after your column.
Example
Table:
Table (2):
Relationship (One to Many):
Result:
I hope this helps.