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
oBi1
Frequent Visitor

DAX - Using SEARCH on a RELATED field in CALCULATETABLE

Hi team

 

Can someone please me help me with this.

I'm using DAX to gerenate a subset of a table - using the following structure:

 

EVALUATE

ADDCOLUMNS(

CALCULATETABLE(

table1,

SEARCH("text",table1[column1],1,0)>0

),

"region", RELATED(table2[Region])

)

 

what I would actually like to do is also 'filter' on a column from the related table (table2). 

This table is related to table1 in the data model. My feable attempt was: to add

search("othertext",RELATED(table2[column2],1,0)>0

after the first SEARCH line (plus adding a , there obviously)

 

Any ideas as it fails...

Thanks!

 

Owen

1 ACCEPTED SOLUTION

Hi @oBi1 ,

 

Please confirm the relationship between table 1 and table 2 and would you please try to use the following dax:

 

EVALUATE
SUMMARIZE (
    FILTER ( table1, SEARCH ( "text", table1[column1], 1, 0 ) > 0 ),
    "region", MAX ( table2[Region] )
)

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

 

View solution in original post

7 REPLIES 7
az38
Community Champion
Community Champion

@oBi1 

are you sure you used this? there is no closing parentheses for RELATED()

 

search("othertext",RELATED(table2[column2] ) ,1,0)>0


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
oBi1
Frequent Visitor

Yes sorry, that was a typo that I missed when typing my question.

 

The error message says: 

25/07/2020 14:28:08 Query (14, 41) The column 'table2[column2]' either doesn't exist or doesn't have a relationship to any table available in the current context.

Hi @oBi1 ,

 

The RELATED function requires that a relationship exists between the current table and the table with related information.

 

https://dax.guide/related/

 

Based on the error , can you confirm if there is an existing relationship.

 

If not then try using lookup.

https://dax.guide/lookupvalue/

 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

 

 

confirmed there is a relationship between table1 and table2

it almost looks like DAX forgets that when inside the CALCULATETABLE statement...

 

Could this be a solution:

instead of doing CALCULATETABLE(table1, SEARCH(....

do: CALCULATETABLE ( table1, RELATEDTABLE(table2), and then start the searches.

not sure if this will hit me in the face in any other way (performancewise or any other hidden gem), but I feel that I need to reconfirm to the DAX engine what the tables are that are used before doing SEARCH functions etc.

 

 

 

 

Hi @oBi1 ,

 

Please confirm the relationship between table 1 and table 2 and would you please try to use the following dax:

 

EVALUATE
SUMMARIZE (
    FILTER ( table1, SEARCH ( "text", table1[column1], 1, 0 ) > 0 ),
    "region", MAX ( table2[Region] )
)

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

 

A really short version of my previous post which due to an internet error did not get posted:

* My Excel crashed before I could try the solution, rendering quite a bit of my work unusable;

* I ended up using another way around this by doing more combination work in Power Query and basically only DAX querying and filtering 1 table from the Data Model

 

Thanks so much for your willingness to reply

Hi @oBi1 ,

 

Thank you for sharing the information. Would you please accept useful reply as answer to help the other members find it more quickly?

 

Best Regards,

Dedmon Dai

 

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.