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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Jp_ON
Frequent Visitor

PathContains from SelectedValue issue with GUID

I have a Table of equipment records that are connected through the Account to Regions.

When I attempt to use the PATHCONTAINS() with SELECTEDVALUE() It always returns False() where if I hard code the GUID it works as expected.

I created a seperate table of Regions to bypass any relationship filtering that may occur.

HeirarchyRegionInPath =
VAR SelectedRegion = "c4be4e26-d198-ec11-b3fe-000d3a09e9da" VS regionselected = SELECTEDVALUE('Region list'[Region])
VAR RelatedRegionPath =
    LOOKUPVALUE(
        ESI_region[HierarchyPath],
        esi_region[Region],
        RELATED(account[esi_territory])
    )
RETURN
IF(
    NOT(ISBLANK(SelectedRegion)) &&
    PATHCONTAINS(RelatedRegionPath, SelectedRegion),
    TRUE(),
    FALSE()
)

Jp_ON_0-1728659892821.png

I must be missing something, all formats are text, tried Column VS measure and only measure would populate RegionSelected

Tried CONTAINSSTRING() rather then PATHCONTAINS(), same result.

Any help appreciated. 

2 ACCEPTED SOLUTIONS

Hi @Jp_ON ,

Thanks for your detailed reply. I updated my sample pbix file, please check if that is what you want. Please update the formula of measure [HeirarchyRegionInPath] as below:

HeirarchyRegionInPath_New = 
VAR _Selectedname =
    SELECTEDVALUE ( 'Region list'[Name] )
VAR _account =
    SELECTEDVALUE ( 'Units'[Account] )
VAR _terr =
    CALCULATETABLE (
        VALUES ( 'esi_region'[esi_territory] ),
        FILTER (
            'esi_region',
            IFERROR ( SEARCH ( _Selectedname, 'esi_region'[Name], 1, 0 ), 0 ) > 0
        )
    )
VAR _accounts =
    CALCULATETABLE (
        VALUES ( 'account'[Name] ),
        FILTER ( 'account', 'account'[esi_territory] IN _terr )
    )
RETURN
    IF ( _account IN _accounts, 1 )

vyiruanmsft_0-1730353968231.png

Best Regards

Community Support Team _ Rena
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

Jp_ON
Frequent Visitor

Took a few rounds but this was what we landed on. 

Have a Table used for Selecting region(Region list) so that the relationships between tables doesn't restrict the avaialble Regions.


Define 

HierarchyPath = PATH(Regions[esi_regionid],Regions[Parent Region (esi_region)])


Then against the Region table this Column is added and we filter the grids based on "RegionInPath is 1"

RegionInPath =
VAR SelectedRegion = SELECTEDVALUE('Region list'[Region])
VAR FilteredTable =
    FILTER(regions, PATHCONTAINS(Regions[HierarchyPath], SelectedRegion))
RETURN
    IF (
        ISBLANK(SelectedRegion),
        1, -- Show all records if no slicer is selected
        IF (
            ISEMPTY(FilteredTable),
            0, -- Record doesn't match filter
            1  -- Record matches filter
        )
    )

View solution in original post

15 REPLIES 15
Jp_ON
Frequent Visitor

Took a few rounds but this was what we landed on. 

Have a Table used for Selecting region(Region list) so that the relationships between tables doesn't restrict the avaialble Regions.


Define 

HierarchyPath = PATH(Regions[esi_regionid],Regions[Parent Region (esi_region)])


Then against the Region table this Column is added and we filter the grids based on "RegionInPath is 1"

RegionInPath =
VAR SelectedRegion = SELECTEDVALUE('Region list'[Region])
VAR FilteredTable =
    FILTER(regions, PATHCONTAINS(Regions[HierarchyPath], SelectedRegion))
RETURN
    IF (
        ISBLANK(SelectedRegion),
        1, -- Show all records if no slicer is selected
        IF (
            ISEMPTY(FilteredTable),
            0, -- Record doesn't match filter
            1  -- Record matches filter
        )
    )
Jp_ON
Frequent Visitor

Thank you for the response. Greatly appreciated. Unfortunately they did not get me to the outcome I'm after.

here is some Example "Region List"

Region list = SELECTCOLUMNS(
    ESI_region,
    "Name", ESI_region[Name],
    "Region", ESI_region[Region]
)

 

NameRegion
Southern Ontario950AA956-C095-EC11-B400-0022486DE339
Ontario8B0AA956-C095-EC11-B400-0022486DE339
Northern Ontario850AA956-C095-EC11-B400-0022486DE339
Central Ontario

750AA956-C095-EC11-B400-0022486DE339

 

And here is the Table of records we're looking to filter by the selected region.

NameRegionHeirarchyRegionInPathHierarchyPath
Unit1OntarioFALSE990AA956-C095-EC11-B400-0022486DE339|C4BE4E26-D198-EC11-B3FE-000D3A09E9DA|710AA956-C095-EC11-B400-0022486DE339|8B0AA956-C095-EC11-B400-0022486DE339
Unit2OntarioFALSE990AA956-C095-EC11-B400-0022486DE339|C4BE4E26-D198-EC11-B3FE-000D3A09E9DA|710AA956-C095-EC11-B400-0022486DE339|8B0AA956-C095-EC11-B400-0022486DE339
Unit3Central OntarioFALSE990AA956-C095-EC11-B400-0022486DE339|C4BE4E26-D198-EC11-B3FE-000D3A09E9DA|710AA956-C095-EC11-B400-0022486DE339|8B0AA956-C095-EC11-B400-0022486DE339|750AA956-C095-EC11-B400-0022486DE339
Unit4Central OntarioFALSE990AA956-C095-EC11-B400-0022486DE339|C4BE4E26-D198-EC11-B3FE-000D3A09E9DA|710AA956-C095-EC11-B400-0022486DE339|8B0AA956-C095-EC11-B400-0022486DE339|750AA956-C095-EC11-B400-0022486DE339
Unit5Northern OntarioFALSE990AA956-C095-EC11-B400-0022486DE339|C4BE4E26-D198-EC11-B3FE-000D3A09E9DA|710AA956-C095-EC11-B400-0022486DE339|8B0AA956-C095-EC11-B400-0022486DE339|850AA956-C095-EC11-B400-0022486DE339
Unit6Northern OntarioFALSE990AA956-C095-EC11-B400-0022486DE339|C4BE4E26-D198-EC11-B3FE-000D3A09E9DA|710AA956-C095-EC11-B400-0022486DE339|8B0AA956-C095-EC11-B400-0022486DE339|850AA956-C095-EC11-B400-0022486DE339



Relationships are as follows.

Jp_ON_2-1728997553866.png

 

 
 

 

 

Hi @Jp_ON ,

Base on your provided data, what's the corrected returned values for the measure [HeirarchyRegionInPath]?


Name Region
Southern Ontario 950AA956-C095-EC11-B400-0022486DE339
Ontario 8B0AA956-C095-EC11-B400-0022486DE339
Northern Ontario 850AA956-C095-EC11-B400-0022486DE339
Central Ontario

750AA956-C095-EC11-B400-0022486DE339

 

Name Region HeirarchyRegionInPath HierarchyPath
Unit1 Ontario FALSE 990AA956-C095-EC11-B400-0022486DE339|C4BE4E26-D198-EC11-B3FE-000D3A09E9DA|710AA956-C095-EC11-B400-0022486DE339|8B0AA956-C095-EC11-B400-0022486DE339
Unit2 Ontario FALSE 990AA956-C095-EC11-B400-0022486DE339|C4BE4E26-D198-EC11-B3FE-000D3A09E9DA|710AA956-C095-EC11-B400-0022486DE339|8B0AA956-C095-EC11-B400-0022486DE339
Unit3 Central Ontario FALSE 990AA956-C095-EC11-B400-0022486DE339|C4BE4E26-D198-EC11-B3FE-000D3A09E9DA|710AA956-C095-EC11-B400-0022486DE339|8B0AA956-C095-EC11-B400-0022486DE339|750AA956-C095-EC11-B400-0022486DE339
Unit4 Central Ontario FALSE 990AA956-C095-EC11-B400-0022486DE339|C4BE4E26-D198-EC11-B3FE-000D3A09E9DA|710AA956-C095-EC11-B400-0022486DE339|8B0AA956-C095-EC11-B400-0022486DE339|750AA956-C095-EC11-B400-0022486DE339
Unit5 Northern Ontario FALSE 990AA956-C095-EC11-B400-0022486DE339|C4BE4E26-D198-EC11-B3FE-000D3A09E9DA|710AA956-C095-EC11-B400-0022486DE339|8B0AA956-C095-EC11-B400-0022486DE339|850AA956-C095-EC11-B400-0022486DE339
Unit6 Northern Ontario FALSE 990AA956-C095-EC11-B400-0022486DE339|C4BE4E26-D198-EC11-B3FE-000D3A09E9DA|710AA956-C095-EC11-B400-0022486DE339|8B0AA956-C095-EC11-B400-0022486DE339|850AA956-C095-EC11-B400-0022486DE339

Best Regards

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

the expecation is that if Ontario(8B0AA956-C095-EC11-B400-0022486DE339) is selected in the Region list because it exists in the HierarchyPath (990AA956-C095-EC11-B400-0022486DE339|C4BE4E26-D198-EC11-B3FE-000D3A09E9DA|710AA956-C095-EC11-B400-0022486DE339|8B0AA956-C095-EC11-B400-0022486DE339) of all those units, they all would have "HeirarchyRegionInPath"= True. The Formula's presented above are what I'm trying to get to represent these conditions/Hierarchy

Hi @Jp_ON ,

I created a sample pbix file(see the attachment), please check if that is what you want.

vyiruanmsft_0-1729156612455.png

Best Regards

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

Really appreciate your assistance on this. It seems that in your pbix that you merged the Unit records and the Region

What I have is Region list that is a table specifically for this selection criteria, so that it doesn't filter based on selected value only.

The relationships of tables are

ESI_Region --> Account --> ESI_UnitRecords

The expectation is to have the selected 'Region List' GUID be matched to any that contain that GUID and Filter/Flag based on that. 

Based on this relationship and the formula you provided as well as all I've tried it doesn't seem to take the Variable of Selctedvalue(), it only seems to work when hard coded.

Hi @Jp_ON ,

Base on your feedback, it seems that my provided method still can't help you get the expected result. Could you please prepare a simiplifed pbix file with the above three tables(ESI_Region --> Account --> ESI_UnitRecords)? You can refer the following link to upload the file to the community. Later I will check the file and provide the solution asap.

How to upload PBI in Community

 

Best Regards

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

let me know if you have any issue accessing or downloading this PBIX

PathContains from SelectedValue issue with GUID.pbix

Hi @Jp_ON ,

I updated the attached file, please check if that is what you want.

 

HeirarchyRegionInPath_New = 
VAR _Selectedname =
    SELECTEDVALUE ( 'Region list'[Name] )
VAR _account =
    SELECTEDVALUE ( 'Units'[Account] )
VAR _terr =
    CALCULATETABLE (
        VALUES ( 'esi_region'[esi_territory] ),
        FILTER (
            'esi_region',
            IFERROR ( SEARCH ( _Selectedname, 'esi_region'[Name], 1, 0 ), 0 ) > 0
            && IFERROR( SEARCH ( 'esi_region'[Region], 'esi_region'[HierarchyPath], 1, 0 ), 0 ) > 0
        )
    ) 

VAR _accounts =
    CALCULATETABLE (
        VALUES ( 'account'[Name] ),
        FILTER ( 'account', 'account'[esi_territory] IN _terr )
    )
RETURN
    IF ( _account IN _accounts, 1 )

 

vyiruanmsft_1-1730354417029.png

Best Regards

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

I'm afraid what you have provided is the same as if I had just allowed the user to select the Region directly.

We need the PathContains(esi_region[HierarchyPath], _SelectedRegion) 

That way if Ontario is selected all units will be displayed as the Guid(region column) from Ontario is in all of the "HierarchyPath" 

Hi @Jp_ON ,

Do you mean all of units should display when the Name slicer select the option "Ontario"? If yes, what's the judgement logic? Could you please explain it with more details? Thank you.

Best Regards

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

absolutely, perhaps my data set was two specific.

The expectation is that when a parent Region is selected,  the units that are assigned to that region, as well as any Child Region that has that Parents GUID in the Path would be shown.

Based on the example Data, all units would show if Ontario was selected. If Central, Unit 4 and 5 would only show, Northern, unit 6, 7, 8 would show, Southern would show no units.

Ontario

----Northern Ontario

----Central Ontario

----Southern Ontario

 

 

let me know if you need anything further. Greatful for your assistance 🙂

Hi @Jp_ON ,

Thanks for your detailed reply. I updated my sample pbix file, please check if that is what you want. Please update the formula of measure [HeirarchyRegionInPath] as below:

HeirarchyRegionInPath_New = 
VAR _Selectedname =
    SELECTEDVALUE ( 'Region list'[Name] )
VAR _account =
    SELECTEDVALUE ( 'Units'[Account] )
VAR _terr =
    CALCULATETABLE (
        VALUES ( 'esi_region'[esi_territory] ),
        FILTER (
            'esi_region',
            IFERROR ( SEARCH ( _Selectedname, 'esi_region'[Name], 1, 0 ), 0 ) > 0
        )
    )
VAR _accounts =
    CALCULATETABLE (
        VALUES ( 'account'[Name] ),
        FILTER ( 'account', 'account'[esi_territory] IN _terr )
    )
RETURN
    IF ( _account IN _accounts, 1 )

vyiruanmsft_0-1730353968231.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-yiruan-msft
Community Support
Community Support

Hi @Jp_ON ,

You can update the formula of measure [HeirarchyRegionInPath] as below, please check if it can return the expected result...

HeirarchyRegionInPath =
VAR SelectedRegion =
    SELECTEDVALUE ( 'Region list'[Region] )
VAR hpath =
    SELECTEDVALUE ( esi_region[HierarchyPath] )
RETURN
    IF (
        NOT ( ISBLANK ( SelectedRegion ) )
            && IFERROR ( SEARCH ( SelectedRegion, hpath, 1, 0 ), 0 ) > 0,
        TRUE (),
        FALSE ()
    )

 

If the above one can't help you figure out, please provide some raw data in your table 'account(exclude sensitive data) with Text format and your expected result with backend logic and special examples base on provided raw data. Is there any relationship between the table 'esi_region' and 'account'? If yes, please provide the relationship info(cardinality, direction etc.). It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
rajendraongole1
Super User
Super User

Hi @Jp_ON - update the IF() logic in the HeirarchyRegionInPath measure

 

HeirarchyRegionInPath =
VAR SelectedRegion = SELECTEDVALUE('Region list'[Region], BLANK()) -- Use SELECTEDVALUE()
VAR RelatedRegionPath =
LOOKUPVALUE(
ESI_region[HierarchyPath],
esi_region[Region],
RELATED(account[esi_territory])
)
RETURN
IF (
NOT(ISBLANK(SelectedRegion)) &&
PATHCONTAINS(RelatedRegionPath, SelectedRegion),
TRUE(),
FALSE()
)

 

if the above is logic not working, can you revisiting the relationships between the tables to ensure that the lookup functions are pulling the correct data.





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

Proud to be a Super User!





Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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