Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
I have two tables in my model each with a column that have matches between the two, however the data is not clean on either side (missing, dupes). I need to create a look-up table that resolves each side properly so that it is a clean 1:* by introducing 'blank' fillers for when data is missing. Normally I would do this all in PowerQuery, however the data sources are distinct and for various reasons I'd like to avoid an additional 'custom' semantic model to resolve this one issue and was hoping I could generate a table 'in memory' with DAX. I realize there can be potential performance pentalities for this type of approach, but I'm not terribly concerned about that risk.
Table A has many columns, but the key is 'IDNo':
| IDNo | [ [...], [, ...] ] |
| 005 | <data> |
| 006 | <data> |
| 007 | <data> |
| 007 | <data> |
| <data> | |
| 008 | <data> |
Table B is effectively identical in scope, just different (but overlapping data):
| IDNo | [ [...], [, ...] ] |
| 003 | <data> |
| 006 | <data> |
| 007 | <data> |
| 008 | <data> |
| 008 | <data> |
| 009 | <data> |
| 0 | <data> |
The end result I'm looking for would look like this:
| IDNoA | IDNoB |
| -1 | 003 |
| 005 | -1 |
| 006 | 006 |
| 007 | 007 |
| 008 | 008 |
| -1 | 009 |
| -1 | 0 |
the value -1 would allow me to return something like 'No Value' or 'N/A' in visuals to avoid any 'hanging' dimensions that would normally resolve as 'blank' in slicers, tables or other visuals, or take other conditional formatting steps with measures.
Any suggestions? I tried a couple of different approaches with no avail, based on the SQLBI guys.
Solved! Go to Solution.
Read about NATURALLEFTOUTERJOIN function (DAX) - DAX | Microsoft Learn
You may have to apply it twice, once from each side.
Your solution is great @lbendlin , Allow me to offer another insight.
Hi, @rpiboy_1
Have you solved your problem? If so, can you share your solution here and mark the correct answer as a standard answer to help other members find it faster. Thank you very much for your kind cooperation!
Perhaps, you can also try the following:
I have the following two tables:
tableA:
table B:
I created a calculated table using the following DAX expression:
LookupTable =
VAR _DistinctIDNo = UNION(
VALUES(TableA[IDNo]),
VALUES('TableB'[IDNo])
)
VAR _CleanDistinctIDNo = DISTINCT(_DistinctIDNo)
RETURN
ADDCOLUMNS (
_CleanDistinctIDNo,
"IDNoA",
VAR _cur= [IDNo]
RETURN IF ( NOT _cur IN VALUES('TableA'[IDNo]),-1, CALCULATE(MAX('TableA'[IDNo]),FILTER(VALUES('TableA'[IDNo]),'TableA'[IDNo]=_cur))),
"IDNoB",
VAR _cur= [IDNo]
RETURN IF ( NOT _cur IN VALUES(TableB[IDNo]) , -1, CALCULATE(MAX('TableB'[IDNo]),FILTER(VALUES(TableB[IDNo]),'TableB'[IDNo]=_cur)))
)
Here are the results:
If you don't want others to see the IDNo column, you can hide it as follows:
I've provided the PBIX file used this time below.
How to Get Your Question Answered Quickly
If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .
Best Regards
Jianpeng Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Your solution is great @lbendlin , Allow me to offer another insight.
Hi, @rpiboy_1
Have you solved your problem? If so, can you share your solution here and mark the correct answer as a standard answer to help other members find it faster. Thank you very much for your kind cooperation!
Perhaps, you can also try the following:
I have the following two tables:
tableA:
table B:
I created a calculated table using the following DAX expression:
LookupTable =
VAR _DistinctIDNo = UNION(
VALUES(TableA[IDNo]),
VALUES('TableB'[IDNo])
)
VAR _CleanDistinctIDNo = DISTINCT(_DistinctIDNo)
RETURN
ADDCOLUMNS (
_CleanDistinctIDNo,
"IDNoA",
VAR _cur= [IDNo]
RETURN IF ( NOT _cur IN VALUES('TableA'[IDNo]),-1, CALCULATE(MAX('TableA'[IDNo]),FILTER(VALUES('TableA'[IDNo]),'TableA'[IDNo]=_cur))),
"IDNoB",
VAR _cur= [IDNo]
RETURN IF ( NOT _cur IN VALUES(TableB[IDNo]) , -1, CALCULATE(MAX('TableB'[IDNo]),FILTER(VALUES(TableB[IDNo]),'TableB'[IDNo]=_cur)))
)
Here are the results:
If you don't want others to see the IDNo column, you can hide it as follows:
I've provided the PBIX file used this time below.
How to Get Your Question Answered Quickly
If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .
Best Regards
Jianpeng Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Read about NATURALLEFTOUTERJOIN function (DAX) - DAX | Microsoft Learn
You may have to apply it twice, once from each side.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.
| User | Count |
|---|---|
| 6 | |
| 6 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 22 | |
| 10 | |
| 10 | |
| 7 | |
| 5 |