Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
basirve
Helper III
Helper III

If the value is N/A then value getting from another table else same tbl but no relationships b/w tbl

Dear Experts,

How to achive below case stament in DAX and no Direct relationships bewteen Table A  , Table B.
basirve_0-1603997030973.png

 

1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@basirve I guess you're thinking of a calculated column.

If you have two tables below

T1

Columna1 Value
A 100
B 200
C Not applicable
D Not applicable

T3

Columna1 Value
C 300
D 400

You can then achieve the equivalent SQL CASE result by creating a column calculated in T1 and usin LOOKUPVALUE/TREATAS/INTERSECT/CONTAINS. None of them have any relationship dependencies. Ensure that thet Value in bith tables have the same data type.

LOOKUPVALUE = 
IF (
    [Value] <> "Not Applicable",
    [Value],
    LOOKUPVALUE ( T3[Value], T3[Column1], T1[Column1] )
)

TREATAS = 
IF (
    [Value] <> "Not Applicable",
    [Value],
    CALCULATE (
        CALCULATE (
            MAXX ( T3, T3[Value] ),
            TREATAS ( VALUES ( T1[Column1] ), T3[Column1] )
        )
    )
)

INTERSECT = 
IF (
    [Value] <> "Not Applicable",
    [Value],
    CALCULATE (
        CALCULATE (
            MAXX ( T3, T3[Value] ),
            INTERSECT ( ALL ( T3[Column1] ), VALUES ( T1[Column1] ) )
        )
    )
)

CONTAINS = 
IF (
    [Value] <> "Not Applicable",
    [Value],
    CALCULATE (
        CALCULATE (
            MAXX ( T3, T3[Value] ),
            FILTER (
                ALL ( T3[Column1] ),
                CONTAINS ( VALUES ( T1[Column1] ), T1[Column1], T3[Column1] )
            )
        )
    )
)

The PBIX is connected.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

6 REPLIES 6
v-eqin-msft
Community Support
Community Support

Hello @basirve ,

In my opinion, you want to get values based on the conditions in another table when the two tables have no relationship, right?

You can use LOOKUPVALUE() as shown below after adding the column from the other table:

B.Emp.ID =
CALCULATE ( ALLSELECTED ( 'B'[Emp.ID] ), FILTER ( 'B', 'B'[ID] = 'A'[ID] ) )
Column =
VAR _COL =
    LOOKUPVALUE ( 'A'[B.Emp.ID], 'A'[ID], [ID] )
RETURN
    IF ( [Emp.ID] IN { "NOT APPLICABLE", "UNKNOWN" }, _COL, [Emp.ID] )

O

Measure =
VAR _c =
    LOOKUPVALUE ( 'A'[B.Emp.ID], 'A'[ID], MAX ( 'A'[ID] ) )
RETURN
    IF (
        MAX ( 'A'[Emp.ID] ) IN { "NOT APPLICABLE", "UNKNOWN" },
        _c,
        MAX ( 'A'[Emp.ID] )
    )

My visualization looks like this:

11.3.5.1.PNG

Here's the pbix file.

Have I answered your question? Please mark my answer as a solution. Thanks a lot.
If not, load some insensitive data samples and expected output.

Best regards
Eyelyn Qin

smpa01
Super User
Super User

@basirve I guess you're thinking of a calculated column.

If you have two tables below

T1

Columna1 Value
A 100
B 200
C Not applicable
D Not applicable

T3

Columna1 Value
C 300
D 400

You can then achieve the equivalent SQL CASE result by creating a column calculated in T1 and usin LOOKUPVALUE/TREATAS/INTERSECT/CONTAINS. None of them have any relationship dependencies. Ensure that thet Value in bith tables have the same data type.

LOOKUPVALUE = 
IF (
    [Value] <> "Not Applicable",
    [Value],
    LOOKUPVALUE ( T3[Value], T3[Column1], T1[Column1] )
)

TREATAS = 
IF (
    [Value] <> "Not Applicable",
    [Value],
    CALCULATE (
        CALCULATE (
            MAXX ( T3, T3[Value] ),
            TREATAS ( VALUES ( T1[Column1] ), T3[Column1] )
        )
    )
)

INTERSECT = 
IF (
    [Value] <> "Not Applicable",
    [Value],
    CALCULATE (
        CALCULATE (
            MAXX ( T3, T3[Value] ),
            INTERSECT ( ALL ( T3[Column1] ), VALUES ( T1[Column1] ) )
        )
    )
)

CONTAINS = 
IF (
    [Value] <> "Not Applicable",
    [Value],
    CALCULATE (
        CALCULATE (
            MAXX ( T3, T3[Value] ),
            FILTER (
                ALL ( T3[Column1] ),
                CONTAINS ( VALUES ( T1[Column1] ), T1[Column1], T3[Column1] )
            )
        )
    )
)

The PBIX is connected.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@basirve did you try the solution provided here ?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Fowmy
Super User
Super User

@basirve 

Can you share some sample data and the expected result to have a clear understanding of your question?
You can save your files in OneDrive, Google Drive, or any other cloud sharing platforms and share the link here.
____________________________________
How to paste sample data with your question?
How to get your questions answered quickly?

_____________________________________
Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

basirve_0-1603998769655.png

 

below logic is not fiting due to no relationship

IF (Table1[Emp.ID] IN {"NOT APPLICABLE","UNKNOWN"},Table2[Emp.ID],Table2[Emp.ID])

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.