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
PowerBeeEye
Employee
Employee

Conditional column based on correlation of data from two columns

I have a table like the one below, where one forest may contain one or more domains. Some of the domains may not have the same contiguous name as the forest (see 5th row)

 

ForestDomain
Contoso.comContoso.com
Contoso.comCorp.Contoso.com
Fabrikam.netFabrikam.net
Fabrikam.netChild.Fabrikam.net
Fabrikam.netFabrikam.com
Fabrikam.netCorp.Fabrikam.com
WingtipToys.caWingtipToys.ca

 

I would like to add two columns, ForestType and DomainType:

 

ForestDomainForestTypeDomainType
Contoso.comContoso.comMulti-domainForest-root
Contoso.comCorp.Contoso.comMulti-domainChild
Fabrikam.netFabrikam.netMulti-domainForest-root
Fabrikam.netChild.Fabrikam.netMulti-domainChild
Fabrikam.netFabrikam.comMulti-domainTree-root
Fabrikam.netCorp.Fabrikam.comMulti-domainChild
WingtipToys.caWingtipToys.caSingle-domainForest-root

 

Logic:

  • ForestType
    • If Forest = Domain, and Forest is unique, ForestType = Single-domain
    • If Forest = Domain, and Forest is not unique, ForestType = Multi-domain
    • If Forest != Domain, ForestType = Multi-domain
  • DomainType
    • If Domain = Forest, DomainType = Forest-root
    • If Domain != Forest, and there is no other Domain value that is a substring, DomainType = Tree-root
    • If Domain != Forest, and there is one or more Domain value that is a substring, DomainType = Child

 

Thanks a ton!

1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi , @PowerBeeEye 

According to you description, you can follow these steps:

1) Constructing three auxiliary columns

forest equal domain = 'Table'[Forest]='Table'[Domain]
forest unique = CALCULATE(COUNTA('Table'[Forest]),ALLEXCEPT('Table','Table'[Forest]))
IS Substring = FIND('Table'[Forest],'Table'[Domain],,-1)

 2)Create calculated columns based on conditions

Forest Type = SWITCH( TRUE(),
'Table'[forest equal domain]=TRUE()&&'Table'[forest unique]= 1,"Single-domain",
'Table'[forest equal domain]=TRUE()&& 'Table'[forest unique] <> 1,"Multi-domain",
'Table'[forest equal domain]=FALSE(),"Multi-domain")
Domain Type = SWITCH( TRUE(),
'Table'[forest equal domain]=TRUE(),"Forest-root",
'Table'[forest equal domain]=FALSE()&& 'Table'[IS Substring]=-1,"Tree-root",
'Table'[forest equal domain]=FALSE()&& 'Table'[IS Substring]>0,"Child")

Here is a sample I  made :

1901.png

URL:https://wicren-my.sharepoint.com/:u:/g/personal/michael_wicren_onmicrosoft_com/Ec-1gyha81hBg848d7QkK...

 

Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-easonf-msft
Community Support
Community Support

Hi , @PowerBeeEye 

According to you description, you can follow these steps:

1) Constructing three auxiliary columns

forest equal domain = 'Table'[Forest]='Table'[Domain]
forest unique = CALCULATE(COUNTA('Table'[Forest]),ALLEXCEPT('Table','Table'[Forest]))
IS Substring = FIND('Table'[Forest],'Table'[Domain],,-1)

 2)Create calculated columns based on conditions

Forest Type = SWITCH( TRUE(),
'Table'[forest equal domain]=TRUE()&&'Table'[forest unique]= 1,"Single-domain",
'Table'[forest equal domain]=TRUE()&& 'Table'[forest unique] <> 1,"Multi-domain",
'Table'[forest equal domain]=FALSE(),"Multi-domain")
Domain Type = SWITCH( TRUE(),
'Table'[forest equal domain]=TRUE(),"Forest-root",
'Table'[forest equal domain]=FALSE()&& 'Table'[IS Substring]=-1,"Tree-root",
'Table'[forest equal domain]=FALSE()&& 'Table'[IS Substring]>0,"Child")

Here is a sample I  made :

1901.png

URL:https://wicren-my.sharepoint.com/:u:/g/personal/michael_wicren_onmicrosoft_com/Ec-1gyha81hBg848d7QkK...

 

Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

HotChilli
Super User
Super User

In Power Query.  For ForestType, you could do a 'group by' as follows

Annotation 2020-01-09 010303.png

Then expand the 'All' column.

Add a Custom Column.

if [Forest] = [All.Domain] and [Count] = 1 then "Single-domain" else "Multi-Domain"

I've shortened the logic you provided but feel free to edit your own version.

 

I might have a go at part 2 if you explain further about the substring logic.

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.