Dax calculation Filling Null based on ID column
Dax calculation Filling Null based on ID column
Real Time Problem:
I have a table that has two main columns: Account ID and Customer Name. The Customer Name column contains a lot of blanks but the Account ID field is complete, so I was wondering if there's a way to get PowerBI to recognise that Account ID 1 is used against the Customer Name, and therefore to fill in any blanks as a result of this? I know this is really confusing, here's an example:
Name AccountID
John 1
So is there a way to get PowerBI to recognise that EmpName = Account ID 1, therefore any rows that have the Account ID 1 should fill any blank cells in the Customer Name column with EmpName?
I want these null cells filled so I can use the Customer Name as a Slicer.
Solution:
Filled_Name =
IF(
ISBLANK('YourTableName'[Name]),
CALCULATE(
FIRSTNONBLANK('YourTableName'[Name], 1),
FILTER(
'YourTableName',
'YourTableName'[Account_ID] = EARLIER('YourTableName'[Account_ID]) &&
NOT(ISBLANK('YourTableName'[Name]))
)
),
'YourTableName'[Name]
)
Explanation:
Filled_Name: This is the name of the calculated column or measure you're creating. It represents the column that will contain the filled names.
IF(ISBLANK('YourTableName'[Name]), ...): This is the start of an IF statement. It checks if the Name column is blank for the current row.
CALCULATE(FIRSTNONBLANK('YourTableName'[Name], 1), ...): If the Name column is blank, this part of the expression calculates the first non-blank Name for the same Account_ID. It uses the CALCULATE function to evaluate an expression in a modified filter context.
FILTER('YourTableName', ...): This function filters the table to rows where the conditions inside the filter function are met.
'YourTableName'[Account_ID] = EARLIER('YourTableName'[Account_ID]) && NOT(ISBLANK('YourTableName'[Name])): This condition filters the table to rows where the Account_ID matches the current row's Account_ID and the Name is not blank.
'YourTableName'[Name]: This is the column being filtered.
'YourTableName'[Name]: If the Name column is not blank, this part of the expression simply returns the original Name.
Comments
Post a Comment