Drill Through By Mapping Fields - powerbi

Say I have Page 'A' and I want to drill through to Page 'B'. Ordinarily I would set up the drill through by specifying the field in page B that "joins" the same field from page A.
I want to do something slightly different. I would like to somehow specify that the User Name column from a table on page A should be used to filter the Manager Name field, from the same table, in page B.
For example, assume on page A, the current User Name is John Smith. On page B I would like the value of John Smith to be used to filter the Manager Name field from the same table.
Is this possible?

This is an interesting prompt. I think one way to do this is to have your [User Name] and [Manager Name] fields in a table in your model with ONLY an inactive relationship on the [Manager Name]. Then, when you filter on the [User Name], you would use DAX calculations that look something like this:
YourMeasure =
IF (
ISFILTERED ( 'NewTable'[User Name] ) = TRUE (),
CALCULATE (
CALCULATE (
[ExistingMeasure],
ALLEXCEPT ( 'NewTable', [Manager Name] ),
USERELATIONSHIP ( 'Table1'[Manager Name], 'NewTable'[Manager Name] )
)
),
BLANK ()
)
The main consideration here is that you'd have to do this for each measure you want to display on Page B.

Related

Use slicer to filter PATHCONTAINS

So I have a table with employees. Each employee has a manager, and using the PATH function, I can create another column, that traces the management of each employee to the CEO (using employee ID and manager's ID.) For example, if my boss reports to the ceo, my employee path would be "CEO ID | My boss ID | My ID" or "10001234|10002345|1000456."
Once I have this path selected, I need to be able to filter my data based on a list of people (business leaders.) If I select business leader A, then I want my data to only include people who have business leader A in their employee path, i.e., people who eventually report to him. I have a separate table of business leaders. Here's what Im doing:
Create a path for each employee: empPath = PATH(EmployeeTable[Employee ID], EmployeeTable[Manager ID])
Use business leader table as a slicer (using their IDs)
Create a variable, selectedLeader, that records the value of whatever selection has been made from the slicer: selectedLeader = IF(HASONEVALUE('LeaderTable'[Id]),VALUES('LeaderTable'[Id]),BLANK())
Put it all together using PATHCONTAINS to filter assign a binary indicator that will allow us to filter the data:
Filter =
var selectedLeader = IF(HASONEVALUE('LeaderTable'[Id]),VALUES('LeaderTable'[Id]),BLANK())
var empPath = PATH(EmployeeTable[Employee ID], EmployeeTable[Manager ID])
return IF(PATHCONTAINS(empPath, selectedLeader ),1,0)
This however, gives the error: Calculation error in measure: A table of multiple values was supplied where a single value was expected.
I've been trying to play around with the formula a lot, using VALUES, FIRSTNONBLANK and other aggregating functions on employeePath, but none are working as desired. Any help appreciated!
The issue is that you need row context for your PATH function to work as you're expecting. As you have it written, it doesn't know which row of the EmployeeTable you're referring to with empPath.
Try this instead:
Filter =
VAR selectedLeader = SELECTEDVALUE ( 'LeaderTable'[Id] )
VAR FilteredTable =
FILTER (
EmployeeTable,
PATHCONTAINS (
PATH ( EmployeeTable[Employee ID], EmployeeTable[Manager ID] ),
selectedLeader
)
)
RETURN
IF ( ISEMPTY ( FilteredTable ), 0, 1 )
You can make this more efficient if you define a calculated path column on the EmployeeTable first.
Path = PATH ( EmployeeTable[Employee ID], EmployeeTable[Manager ID] )
Then the measure simplifies to:
Filter =
VAR selectedLeader = SELECTEDVALUE ( 'LeaderTable'[Id] )
VAR FilteredTable =
FILTER ( EmployeeTable, PATHCONTAINS ( EmployeeTable[Path], selectedLeader ) )
RETURN
IF ( ISEMPTY ( FilteredTable ), 0, 1 )

How to filter a dimension based on RLS applied to another dimension?

Assume I have 2 dimension tables and 1 fact table.
DimUser
DimClients
DimCompany
FactSales
All the dims have a 1:M relation with filter flowing from the 1 -> M side.
Assume I have configured RLS filter on DimUser ([Username] = USERNAME()) so that the user of the report can see his own data based on email address, so user can see his own record entry in DimUser. Thus it will auto filter the FactSales also, effectively the user will be able to see only his sales.
However the user can see all clients and companies in the slicer. I want to setup filter on the DimClients and DimCompany so that the user can see only clients and conpanies for which he has made sales. How can I achieve this?
For example:
How to apply RLS to the DimClients and DimCompany so that it will filter only those ClientIds that appear in the sales table based on dynamic filter [Username] = USERNAME() applied on the DimUsers table?
The other option is to enable bidirectional filtering but this is not allowed for multiple tables.
You can create a measure that looks like this:
UserFlag =
CONTAINSSTRING (
CONCATENATEX ( FactSales, RELATED ( DimUsers[UserEmail] ), "," ),
USERNAME()
)
Create your RLS role and add this filter to each dimension.
[UserFlag] = True()
The result: If a row from a dimension is related to a fact row that is in turn related to the DimUser row whose email matches USERNAME(), then the measure returns 'True.' And so RLS is filtering only to those rows.

DAX Count Max Value By Group

I have a survey that is sent to companies periodically and each new survey is given a collection #. I'm trying to create a column that tells me the maximum collection # for each company code. This will vary by company because not every company responds to every survey.
LastCollection = (FILTER('Dynamic', 'Dynamic'[Collection]
=CALCULATE(max('Dynamic'[Collection]),ALLEXCEPT('Dynamic','Dynamic'[Company Name])))
The error I'm getting is that the expression refers to multiple columns. I attempted to wrap it in AVERAGE but that didn't help.
You should just be able to do something along the lines of the below.
LastCollection =
VAR companyName = 'Dynamic'[Company Name]
RETURN CALCULATE( MAX ('Dynamic'[Collection] ),
FILTER ( 'Dynamic', 'Dynamic'[Company Name] = companyName ))
I'm not sure why you have the CALCULATE inside a FILTER since a FILTER returns a table rather than a single value.
This should be simpler:
LastCollection =
CALCULATE (
MAX ( 'Dynamic'[Collection] ),
ALLEXCEPT ( 'Dynamic', 'Dynamic'[Company Name] )
)

DAX - add column with most common value

In Power BI, I have table with following data, columns "Company", "Document", "Link", "Price", "Document Category"
Example:
I need to add new column (for example Company Category), where will be most accured value of "Document Category" depend on "Company" and with rule, that "Link" column value is not empty.
So the new table would look like this:
Company A, most common value of "Document Category" (where link is
not empty) is "Car"
Company B has "Airplane"
Company C has "Other"
It's possible to add new column for this case in Power BI via DAX?
This is similar to the question I linked in the comments. For each Company, you want to count how many times each Document Category appears and then pick the top one.
Company Category =
VAR CurrRowCompany = Table1[Company]
VAR DocumentCategories =
SUMMARIZE (
FILTER ( Table1, Table1[Company] = CurrRowCompany ),
Table1[Document Category],
"DocCount", COUNT ( Table1[Document Category] )
)
RETURN
SELECTCOLUMNS (
TOPN ( 1, DocumentCategories, [DocCount] ),
"Category", Table1[Document Category]
)

How to filter Power BI table using list of keywords (in a column in other table)

I have a big data table with a column called Account Name. In another table (Accounts) I have a column of Account Keywords that contains parts of full account names. I want to filter the big data by column 'Account Name' using the list of keywords in the 'Acount Keywords' list.
I've created a new measure in the big data table called 'Filter Accounts' with the following DAX:
FILTER ACCOUNTS = contains(Accounts,Accounts[Account Keyword],Big_Data[Account Name])
But the "contains" function works on exact matches. I want it to return true if the 'Account Keyword' is found within any part of the 'Account Name' field. I also want it to ignore case.
The DAX statement results in TRUE only for exact matches. How do I modify my DAX to achieve the desired non-exact matches?
DAX has two functions for text contains matching, CONTAINSSTRING and CONTAINSSTRINGEXACT, where the latter is case-sensitive but the former is not.
You can find how many keywords match an Account Name by writing a calculated column like this on the Big_Data table:
Keyword Matches =
COUNTROWS (
FILTER (
Accounts,
CONTAINSSTRING ( Big_Data[Account Name], Accounts[Account Keyword] )
)
)
To get a TRUE or FALSE output instead of a count, simply append > 0 to see if the count is a positive value.
Match Exists =
COUNTROWS (
FILTER (
Accounts,
CONTAINSSTRING ( Big_Data[Account Name], Accounts[Account Keyword] )
)
) > 0