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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
skingi20
Regular Visitor

Select a value in a column, then filter a the table by the value of another column in the same row

I have a dataset called address_station:

addressstation
rocky road 1, New York100
rocky road 2, New York100
rocky road 3, New York100
streetway 1, Manchester200
streetway 2, Manchester200
streetway 3, Manchester200
other road 1, Germany300
other road 1, Germany400
happy road 1, Germany300
happy road 2, Germany300
happy road 3, Germany300
sad road 1, Germany400
sad road 2, Germany400
sad road 3, Germany400

 


I use a slicer on this dataset to select 1 and only 1 address. For instance I select rocky road 1, New York.
I then want to return a table, that is filtered on the data, such that all of the rows which has the same station as rocky road 1, New York, gets returned. Like this:

addressstation
rocky road 1, New York100
rocky road 2, New York100
rocky road 3, New York100


This is the main problem and what I mainly want to do. Though if possible I also have some special cases I would like to handle. For instance as can be seen "other road 1, Germany" appears twice with different stations. If this road is selected I want this returned. i.e. all the stations associated with that address.

other road 1, Germany300
other road 1, Germany400
happy road 1, Germany300
happy road 2, Germany300
happy road 3, Germany300
sad road 1, Germany400
sad road 2, Germany400
sad road 3, Germany400


I have tried using DAX meausures and DAX tables.
Measure 1:

SelectedAddress =
SELECTEDVALUE('address_station'[Address])

Measure 2:
SelectedStation =
VAR SelectedAdressValue = [SelectedAddress]
RETURN
CALCULATE(
    SELECTEDVALUE('address_station'[Station]),
    'address_station'[Address] = SelectedAdressValue
)

Measure table:
FilteredAdresses =
VAR SelectedStationValue = [SelectedStation]
RETURN
    CALCULATETABLE(
        'address_station',
        'address_station'[Station] = SelectedStationValue
        )


The two measures work fine and returns the expected value, but the measure table returns the same thing, no matter the selection.
1 ACCEPTED SOLUTION
skingi20
Regular Visitor

I found the solution after your hints and some more googling. Apparently I had to remove the duplicates in Address to get the right results, since it does not work to return multiple stations I think. So this problem is still unsolved, if there is multiple stations for each address. Or more generally multiple adults to the same child.
Well on to the solution:

I found this thread which was quite helpful:
https://community.fabric.microsoft.com/t5/Desktop/Filtering-a-parent-based-on-the-child/td-p/2317956

And in specifics how I did it:
First I created a calculated table like this:

Slice_Table = DISTINCT('address_station'[address])

Then this measure:
Flag =
var _addressselect=SELECTEDVALUE('Slice_Table'[address])
var _station=CALCULATE(MAX('address_station'[station]),FILTER(ALL(address_station),'address_station'[address]=_addressselect))
return
IF(
    MAX('address_station'[station])=_station,1,0)

Put the Slice_Table address in the slicer:
skingi20_0-1721379483030.png

And putting the flag = 1 in the visual:

skingi20_1-1721379524923.png

 

 

View solution in original post

7 REPLIES 7
skingi20
Regular Visitor

I found the solution after your hints and some more googling. Apparently I had to remove the duplicates in Address to get the right results, since it does not work to return multiple stations I think. So this problem is still unsolved, if there is multiple stations for each address. Or more generally multiple adults to the same child.
Well on to the solution:

I found this thread which was quite helpful:
https://community.fabric.microsoft.com/t5/Desktop/Filtering-a-parent-based-on-the-child/td-p/2317956

And in specifics how I did it:
First I created a calculated table like this:

Slice_Table = DISTINCT('address_station'[address])

Then this measure:
Flag =
var _addressselect=SELECTEDVALUE('Slice_Table'[address])
var _station=CALCULATE(MAX('address_station'[station]),FILTER(ALL(address_station),'address_station'[address]=_addressselect))
return
IF(
    MAX('address_station'[station])=_station,1,0)

Put the Slice_Table address in the slicer:
skingi20_0-1721379483030.png

And putting the flag = 1 in the visual:

skingi20_1-1721379524923.png

 

 

Samarth_18
Community Champion
Community Champion

Hi @skingi20 ,

 

You could try the following:-

FilteredAddressesTable =
VAR SelectedStationValue = [SelectedStation]
RETURN
ADDCOLUMNS(
    FILTER(
        'address_station',
        'address_station'[station] = SelectedStationValue
    ),
    "Address", 'address_station'[address],
    "Station", 'address_station'[station]
)

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

As the code is there it does not work when creating a dax table. I also have tried to change a few things in it to fix the errors, but it still does not give the intended result. Could you clarify further what this is or is supposed to be?

@skingi20 , To answer specifically could you please share the expected output sample?

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

The expected output sample is in my original post? Is there any more information you need?

amitchandak
Super User
Super User

@skingi20 , A calculated table cannot use measure values to filter. Tables are static in nature and are loaded at data load, so any change in slicer will not change the values.

Arh okay, many thanks! Is there then another solution to this problem, which does not involve filtering in a table?

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

August Carousel

Fabric Community Update - August 2024

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