Does using fact tblname in all DAX fucntions result in table expansion? - powerbi

Given a model with fact table having multiple dimension tables, Does using the fact tblname in all DAX fucntions result in table expansion?
Example:
SUMX(tblname, expr)
CALCULATE(expr, FILTER(tblname, criteria))

Yes, when a relationship exists, there is an expanded table.
In the first example
SUMX(tblname, expr)
the iterator creates a row context over the tablname. RELATED must be used to access fields in the tblname expanded tables that are not parte of tablename, but reachable through a many to one relationship.
in the second example
CALCULATE(expr, FILTER(tblname, criteria))
the FILTER is an iterator and therefore it works like in the first example.
The table returned by FILTER inside CALCULATE acts as an expanded table, therefore affecting not only the existing filters over tblname, but also the existing filters over the columns that are part of the tblname expanded table.
For instance, assuming to have a model with a table Customers and a table Sales with a one to many relationship between Customers and Sales, in this code
CALCULATE([Sales Amount], FILTER(ALL(Sales), Sales[Quantity] > 2))
the FILTER returns a filtered Sales expanded table that removes any existing filter over Customers table.

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

Using a filter with a selection measure returning empty table

I am attempting to filter a table as follows:
Table = Filter(Cashflows, Cashflows[Basis] = Cashflows[Basis Selection 1])
My selection measure is as follows:
Basis Selection 1 = SELECTEDVALUE('Basis CF1'[Value])
Basis CF1 is a slicer I have created from a table. My issue is that the filter returns only an empty table.
Thanks
Note that you cannot calculate tables dynamically at query time that are persisted to the data model. Calculated tables and calculated columns are calculated exactly once, which is at (data set) refresh time.
I suspect that at refresh time there is no valid SELECTEDVALUE for 'Basis CF1'[Value]. This makes the function return a BLANK() (since you have not used the optional second argument), and your FILTER function filters the Cashflows table on rows where Cashflow[Basis] is blank. Perhaps there are no such rows, leading to a blank table being returned.

How to resolve `single value for column cannot be determined` error?

DimUser and DimCustomer filter the FactSales table.
I have created a RLS role with the following DAX on the DimCustomer table:
[DW_CustomerID] IN
SELECTCOLUMNS(FILTER(Dimuser,DimUser[User_Email]=USERPRINCIPALNAME())
, "DW_CustomerID", FactSales[DW_CustomerID])
My intention is to filter the DimUser based on the current user's email, then retrieve the filtered Customer ID's from the FactSales table. Effectively the logged in user can only those customer for the user has made sales.
The DAX is giving following error:
A single value for column DW_CustomerID in table FactSales cannot be
determined.
How to resolve this error?
You are looking for a column that does not exist in the table you are looking for it in. The first parameter of the SELECTCOLUMNS() function is a table, in your case you have provided a derived table built by the FILTER() function being used on the DimUser table. Therefore, your derived table is one row with all the columns from the DimUser table. The FactSales[DW_CustomerID] column is not in this table.
I would try rewriting it to be something closer to the following:
[DW_CustomerID] IN
CALCULATETABLE(
VALUES(FactSales[DW_CustomerID]),
DimUser[User_Email] = USERPRINCIPALNAME()
)
Without seeing your model it is tough to know for sure though.

Making column reference via slicer

I have a table with two choices 'FLOW_CONTEXT' and 'TEST_NAME'.
I want to let the user select one of these values using a slicer. I then want to have a calculated formula point to either the 'FLOW_CONTEXT' or the 'TEST_NAME' column in another table. There is a 1:1 relationship between the 'FLOW_CONTEXT' and the 'TEST_NAME' columns in the table.
Here is the column formula I have, which always defaults to false, even though the SELECTEDVALUE part of the IF statement does work (checked via a card):
COLUMN_POINTER = IF(
SELECTEDVALUE(TEST_NAME_FIELD[TEST_NAME_FIELD]) = "FLOW_CONTEXT",
CCD_BINNING_TEST_RESULTS_LAST_RANK[FLOW_CONTEXT],
CCD_BINNING_TEST_RESULTS_LAST_RANK[TEST_NAME]
)
I have tried doing this with a measure but measures only see non-categorical columns. Thx much.
Columns are only calculated at refresh time - they do not respond to slicers filters in this way. You cannot re-calculate a column based on a selected value in a table visual.
You need to transform your use-case into a measure-friendly approach.

Can I add a filter to a SELECTCOLUMNS so that I can use two different table depending on the filter in DAX

I am using DAX Studio and I would like to add a filter to the table field in SELECTCOLUMNS so that it using two different table depending on the filter's expression result.
In other words what I would like to do is similar to the following :
DEFINE
VAR cond_talble =
SELECTCOLUMNS(
IF(#param1="1",TABLE1,TABLE2),
"column1",[column1],
"column2",[column2]
)
Thank you kindly
there is a work around for this problem but might not be a good one for everyone, and it's to add a column in both tables containing a boolean that is set to true for table1 and 0 for table2 and then (if your trables contains the same columns like me) get a table that is the fruit of the union of both tables and add an if condition on a filter so that you filter with the added column