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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
razieh1990
Helper I
Helper I

Display based on the selected values from filter

Hello 

 

below is my data :

I have six cities and each city belongs to one region, each city has a status and each region has a status as well.

I have a slicer in Power BI and it filters the data based on "CITY"

QUESTION :

I want to create a measure to display the status of the city if I select one city only from the slicer if I choose CITY 1 and 2 from the slicer, it shows the region status which is "O" and if I choose two cities from different regions it should display blank.

 

here is the measure I Wrote but not working :

 

ss=

var count_rows= countrows(distinct(table[city])

var filtervalues= values(table[city])

return 

if(and(count_rows>1 , filtervalues in {1,2,3}, calculate(max(table[region status])),
if (and(count_rows>1 , filtervalues in {4,5,6}, calculate(max(table[region status])),calculate(max(table[region status]))))

I would appreciate it if you could help me. 

CITYREGION CITY STATUS REGION STATUS 
1ontFO
2ontFO
3ontOO
4westOF
5westFF
6westFF
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @razieh1990 ,

The Table data is shown below:

vzhouwenmsft_0-1720144621462.png

Please follow these steps:

1.Use the following DAX expression to create a table

Table 2 = VALUES('Table'[CITY])

vzhouwenmsft_1-1720144688990.png

vzhouwenmsft_2-1720144731639.png

2.Use the following DAX expression to create a measure

Measure = 
VAR _table = SELECTCOLUMNS('Table',"Region",[REGION ])
VAR _isSameRegion = COUNTROWS(DISTINCT(_table))
VAR _city = SELECTEDVALUE('Table 2'[CITY])
RETURN 
IF(NOT ISFILTERED('Table'[CITY]),
    MAXX(FILTER('Table',[CITY] = _city),[REGION ]),
    IF(_isSameRegion = 1,
        MAXX(FILTER('Table',[CITY] = _city),[REGION ]),BLANK()
    )
)

3.Final output

vzhouwenmsft_3-1720144802661.png

vzhouwenmsft_4-1720144815463.png

Best Regards,
Wenbin Zhou
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

1 REPLY 1
Anonymous
Not applicable

Hi @razieh1990 ,

The Table data is shown below:

vzhouwenmsft_0-1720144621462.png

Please follow these steps:

1.Use the following DAX expression to create a table

Table 2 = VALUES('Table'[CITY])

vzhouwenmsft_1-1720144688990.png

vzhouwenmsft_2-1720144731639.png

2.Use the following DAX expression to create a measure

Measure = 
VAR _table = SELECTCOLUMNS('Table',"Region",[REGION ])
VAR _isSameRegion = COUNTROWS(DISTINCT(_table))
VAR _city = SELECTEDVALUE('Table 2'[CITY])
RETURN 
IF(NOT ISFILTERED('Table'[CITY]),
    MAXX(FILTER('Table',[CITY] = _city),[REGION ]),
    IF(_isSameRegion = 1,
        MAXX(FILTER('Table',[CITY] = _city),[REGION ]),BLANK()
    )
)

3.Final output

vzhouwenmsft_3-1720144802661.png

vzhouwenmsft_4-1720144815463.png

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

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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