How to make a existing column "unique" in PowerBI, so I can form a "one-to-many" relationsship? - powerbi

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.

Related

Power BI LOOKUPVALUE with a column of values for the search items? (VLOOKUP alternative)

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]
)

How to add a new column with custom values, based on a WHERE clause from another table in PowerBi?

I am stuck while dynamically forming a new column based certain WHERE clause from another Table in PowerBi. To give more details, let's say I have a table with item numbers associated with a Customer Name. In another table, I have to add a new column, which will dynamically add the item numbers associated with a particular customer and append as a query parameter to a base url.
So, my first table looks like this:
The second table that I want is this:
The query parameter value in the URL, has to be dynamically based on a SELECT query with a WHERE clause and pick up the ItemNumbers using the Customer field which is common between both. So, how can this be done in PowerBi? Any help would be really appreciated :)
I have one table in my model "TableRol" if I want to summarize my Date as the string I can use CONCATENATEX;
URL = CONCATENATE(CONCATENATE("http:\\mysite.com\parametersHere\getitem?='",CONCATENATEX(VALUES('TableRol'[Date]), 'TableRol'[Date],";")),"'")

Order by a field which isn't included on a matrix POWERBI

I'm trying to build a matrix on PowerBI and I want to order the data by a field which I don't want to include in the matrix. My field named "category" in the matrix must be on a especific order, and I create a numeric field to specify the order. But when I want to order by that numeric field, I can't, PowerBI only allows me to order by the field which is in the matrix.
To test it, I concatenated my numeric field with the category like this: numeric - category, and it works, but I don't want to show it like that, I want only the category field order by the numeric field.
Any suggestion? Thanks.
EDIT:
I have also tried with "Sort by column", but neither selecting the matrix nor the data source table, the button is not activated.
Also detail that "category" has 2 or more numbers in "order" column.
"Sort by column" was not activated because there were many duplicated rows in "Category" field, so I couldn't sort by "Order" because 2 or more rows share the same "category" with different "Orders". I fixed my database and now I can use the tool.

How to substitute NULL with value in Power BI when joining one to many

In my model I have table AssignedToUser that don't contain any NULL values.
Table TotalCounts contains number of tasks for each User.
Those two table joined on UserGUID, and table TotalCounts contains NULL value for UserGUID.
When I drop everything in one table there is NULL value for AssignedToUser.
How can I substitute value NULL for AssignedToUser for "POOL".
Under EditQuery I tried to Create additional column
if [AssignedToUser] = null then "POOL" else [AssignedToUser]
But that didnt help.
UPDATE:
Thanks Alexis.
I have created FullAssignedToUsers table, but when I try to make a relationship with TotalCounts on UserGUID - it doesnt like it.
Data in new a table looks like this:
UPDATE:
File .ipbx can be accessed here:
https://www.dropbox.com/s/95frggpaq6tce7q/User%20Open%20Closed%20Tasks%20Experiment.pbix?dl=0
I believe the problem here is that your join has UserGUID values that are not in your AssignedToUsers table.
To correct this, one possibility is to replace your AssignedToUsers table with one that contains all the UserGUID values from the TotalCounts table.
FullAssignedToUsers =
ADDCOLUMNS(VALUES(TotalCounts[UserGUID]),
"AssignedToUser",
LOOKUPVALUE(AssignedToUsers[AssignedToUser],
AssignedToUsers[UserGUID], TotalCounts[UserGUID]))
The should get you the full outer join. You can then create the custom column like you described in the table and use that column in your visual.
You'll probably want to break the relationships with the original AssignedToUsers table and create relationships with the new one instead.
If you don't want to take that extra step, you can do an ISBLANK inside your new table formula.
FullAssignedToUsers =
ADDCOLUMNS(VALUES(TotalCounts[UserGUID]),
"AssignedToUser",
IF(
ISBLANK(
LOOKUPVALUE(AssignedToUsers[AssignedToUser],
AssignedToUsers[UserGUID], TotalCounts[UserGUID])),
"POOL",
LOOKUPVALUE(AssignedToUsers[AssignedToUser],
AssignedToUsers[UserGUID], TotalCounts[UserGUID])))
Note: This is equivalent to doing a right outer join merge on the AssignedToUsers table in the query editor and then replacing the nulls with "POOL". I'd actually recommend approaching it that way instead.
Another way to approach it is to pull the AssignedToUser column over to the TotalCounts table in a custom column and use that column in your visual instead.
AssignedToUsers =
IF(ISBLANK(RELATED(AssignedToUsers[AssignedToUser])),
"POOL",
RELATED(AssignedToUsers[AssignedToUser]))
This is equivalent to doing a left outer join merge on the TotalCounts table in the query editor, expanding the AssignedToUser column, then replacing nulls with "POOL" in that column.
In Dax missing values are Blank() not null. Try this:
=IF(
ISBLANK(AssignedToUsers[AssignedToUser]),
"Pool",
AssignedToUsers[AssignedToUser]
)

Work with matrix (I can't edit visualisation)

I have this table in Power BI, But I can't do another table.
How I can do this?
Now the values are grouped by date (different fields have information under one date, next the same fields are grouped by another date)
I want the values in the columns to be grouped by field (one field has date information next to it).
Edit1:
I can't set Date on the 2nd place in the grouping
Because date is column, traffic,orders,rev,costs- are values
You need to set Date on the 2nd place in the grouping, after a field containing traffic, orders, etc.
EDIT:
You need to unpivot these columns first, for example, in PowerQuery. Use Edit Query. This results in transforming your 4 columns to 2: Attribute and Value. Attribute will be your first grouping parameter. 2nd will be Date. Value column goes to values.
If you need your source query somewhere else, you may create new query for this very report only. It is done by first right-clicking original one and selecting Reference Query, and the doing any edits. This will keep original query intact.