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
Tybaal
Helper II
Helper II

Filter data with an other table condition

Hello, 

 

I'd like to make something seems simple but I do not reach my goal...

I have to display data in a column with a condition on a column from an other table.

 

Example : 

if ('Dimension 1'[field 1] = 'X'; 'Dimension 2'[field 1])

else if (('Dimension 1'[field 1] = 'Y'; 'Dimension 2'[field 2])

 

Someone to help me?

(sorry I know that it seems simpke but I'm a beginner)

 

Thank you in advance.

1 ACCEPTED SOLUTION

Hi @Tybaal ,

 

Try the following formula:

Column =
IF (
    RELATED ( ContractType[ContractType] ) = "X";
    RELATED ( 'Condition'[ConditionX] );
    IF (
        RELATED ( ContractType[ContractType] ) = "Y";
        RELATED ( 'Condition'[ConditionY] )
    )
)

 

If you only have two conditions then the formula can be.

Column =
IF (
    RELATED ( ContractType[ContractType] ) = "X";
    RELATED ( 'Condition'[ConditionX] );
    RELATED ( 'Condition'[ConditionY] )
)

 

Check PBIX file with both versions

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

7 REPLIES 7
Fowmy
Super User
Super User

@Tybaal 

You need to provide more detail as to how your model is setup. If the value is X in Dimension 1 to go and get value from Dimension2, either there should be a relationship that you can use to get the value using the RELATED function or a condition to search value using a function like LOOKUPVALUE?

Better share some dummy data showing both the tables and the expected output.

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

Thank you for your answers.

I will detail more 🙂

In fact I have 2 dimensions, both are linked to a fact table in my model :

I want to create a new column in my fact table with this logic : 

 

New fact table column = If ('Dim contract type'[ContractType code] = 'P'; 'Dim Terms'[P Term])

                                         Else if ('Dim contract type'[ContractType code] = 'S'; 'Dim Terms'[S Term])

 

 

@Tybaal 

Can you try this code to create a new column in the Fact Table:

New fact table column = 
If (
    RELATED('Dim contract type'[ContractType code]) = 'P', 
    RELATED('Dim Terms'[P Term]),
    
    if (
        RELATED('Dim contract type'[ContractType code]) = 'S',
        RELATED('Dim Terms'[S Term]))
)

 

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

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

Thank you for your help.

Unfortunately, I tried your proposition and it still doesn't work.

I made this schema :

Tybaal_0-1599484693588.png

Have you another idea?

Hi @Tybaal ,

 

Try the following formula:

Column =
IF (
    RELATED ( ContractType[ContractType] ) = "X";
    RELATED ( 'Condition'[ConditionX] );
    IF (
        RELATED ( ContractType[ContractType] ) = "Y";
        RELATED ( 'Condition'[ConditionY] )
    )
)

 

If you only have two conditions then the formula can be.

Column =
IF (
    RELATED ( ContractType[ContractType] ) = "X";
    RELATED ( 'Condition'[ConditionX] );
    RELATED ( 'Condition'[ConditionY] )
)

 

Check PBIX file with both versions

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @Tybaal ,

 

I'm assuming that the tables are related by a contract number? what is the link between the fact and the dimensions tables?

 

Looking at your request I assume that you would need to use a lookup to get the data but the lookup needs to have the common link (is similar to VLOOKUP in excel).

 

Can you share a small data sample?

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



MFelix
Super User
Super User

Hi @Tybaal ,

 

This type of filtering is possible however there is the need of more information. Can you please share a sample of your data and expected result? I'm assuming that there is some common field between both tables that allow for you to get the filtering.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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.