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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
schwartzaw
New Member

SELECTEDVALUE with the new Card Category field not responding as expected

I'm getting weird results with a DAX calculation I'm using for conditional formatting of the new card type and having trouble finding a relevant answer.

My data is in two tables:

Metric (a dimension table)

MetricIDMetricName
1All Issues
2High Severity Issues

 

MetricFact (my fact table)

MetricIDMeasureDateMeasureValue
11/1/2610
12/1/2620
13/1/2630
21/1/262
22/1/264
23/1/262

 

The two are connected by the MetricID field and on the Metric table I've added a piece of DAX that dynamically determines the color:

 

WhatColor =

VAR SV = SELECTEDVALUE(Metric[MetricName])

RETURN
   SWITCH(SV,
          "All Issues","blue",
          "High Severity Issues","red",
          "yellow")

 

The problem is, this works great with a matrix visual, but if I try to use it to conditionally format the cards, it always turns them yellow implying a single value for SELECTEDVALUE() is not available. How do I get the category for each card successfully to determine the color if SELECTEDVALUE() doesn't return it?

1 ACCEPTED SOLUTION
divyed
Super User
Super User

Hello @schwartzaw ,

 

The reason your card visual is defaulting to yellow is likely due to filter context.In a Matrix visual, each row or column provides a specific context , hence SELECTEDVALUE can easily identify which metric is being looked at. But, a Card visual summarizes your entire dataset into a single value. Unless you have a Slicer or a Filter on the page selecting exactly one Metric Name, SELECTEDVALUE returns a blank, which triggers your  default.

 

Here is how you can handle : update your dax 

 

WhatColor New =
VAR SV = SELECTEDVALUE(Martic[MatricName], "None")
RETURN
    SWITCH(SV,
        "All Issues", "blue",        
        "High Severity Issues", "red",
        "None", "Grey",              
        "yellow"                      
    )
 
so when nothing is selected, it will give grey but when you select from matrix it will give requried conditional formatting. 
 
divyed_0-1775977843755.png

 

divyed_1-1775977865239.png

 

I have shared an example above , you can update as per need.

 

Specific to your case : 

Please note, when you put multiple metrics into a single New Card visual, the visual calculates your DAX measure once for the entire card, not separately for each individual value or data bar inside it. so better to use 2 separate measures to use it under series values for conditional formatting.

 

Color_AllIssues =
IF(
    CALCULATE(COUNTROWS(MatricFact), Martic[MatricName] = "All Issues") > 0,
    "blue",
    "yellow"
)
 
Color_HSIssues =
IF(
    CALCULATE(COUNTROWS(MatricFact), Martic[MatricName] = "High Severity Issues") > 0,
    "red",
    "yellow"
)
 
divyed_2-1775978636552.png

 

 

I hope this helps.

 

Cheers.

 

Did I answer your query ? Mark this as solution to make it available for others.

 

 

LinkedIn : https://www.linkedin.com/in/neeraj-kumar-62246b26/

View solution in original post

9 REPLIES 9
jespervb7
Regular Visitor

Yea I am curious about this too, is this intended behaviour?

divyed
Super User
Super User

Hello @schwartzaw ,

 

The reason your card visual is defaulting to yellow is likely due to filter context.In a Matrix visual, each row or column provides a specific context , hence SELECTEDVALUE can easily identify which metric is being looked at. But, a Card visual summarizes your entire dataset into a single value. Unless you have a Slicer or a Filter on the page selecting exactly one Metric Name, SELECTEDVALUE returns a blank, which triggers your  default.

 

Here is how you can handle : update your dax 

 

WhatColor New =
VAR SV = SELECTEDVALUE(Martic[MatricName], "None")
RETURN
    SWITCH(SV,
        "All Issues", "blue",        
        "High Severity Issues", "red",
        "None", "Grey",              
        "yellow"                      
    )
 
so when nothing is selected, it will give grey but when you select from matrix it will give requried conditional formatting. 
 
divyed_0-1775977843755.png

 

divyed_1-1775977865239.png

 

I have shared an example above , you can update as per need.

 

Specific to your case : 

Please note, when you put multiple metrics into a single New Card visual, the visual calculates your DAX measure once for the entire card, not separately for each individual value or data bar inside it. so better to use 2 separate measures to use it under series values for conditional formatting.

 

Color_AllIssues =
IF(
    CALCULATE(COUNTROWS(MatricFact), Martic[MatricName] = "All Issues") > 0,
    "blue",
    "yellow"
)
 
Color_HSIssues =
IF(
    CALCULATE(COUNTROWS(MatricFact), Martic[MatricName] = "High Severity Issues") > 0,
    "red",
    "yellow"
)
 
divyed_2-1775978636552.png

 

 

I hope this helps.

 

Cheers.

 

Did I answer your query ? Mark this as solution to make it available for others.

 

 

LinkedIn : https://www.linkedin.com/in/neeraj-kumar-62246b26/
Kedar_Pande
Super User
Super User

@schwartzaw 

Card visuals have no row context - SELECTEDVALUE needs filter context from MetricID/MetricName.

 

WhatColor = 
VAR MetricName = VALUES(Metric[MetricName])
RETURN
SWITCH(
TRUE(),
COUNTROWS(MetricName) = 1 && "All Issues" IN MetricName, "blue",
COUNTROWS(MetricName) = 1 && "High Severity Issues" IN MetricName, "red",
"yellow"
)

Matrix works because row context creates filter context per MetricID. Cards need explicit filter (slicer on MetricName) or this VALUES approach.

Better - add MetricName slicer above cards. SELECTEDVALUE works perfectly with slicer filter context.

@Kedar_Pande , while continuing to try to understand what's going on with the card, I created a new page to use as a tooltip and assigned it to the Card as the tooltip. This worked exactly as expected, filtering the tooltip by the name of the Metric I was hovering over. It seems like the card has the ability to share the appropriate context with a tooltip. I'm not sure what exactly this tells me about the card visual and what I should be expecting in DAX, but figured I'd add that info in.

Thank you. I think this offers the clearest explanation of why what I'm trying doesn't work - the new card does not create a row context when I add something to the categories field. That said, I tried the code you provided and it didn't produce the desired result unfortunately.

cengizhanarslan
Super User
Super User

The behavior is the same root cause as SELECTEDVALUE failing when multiple rows exist in context. You could use MAX instead of SELECTEDVALUE() for it to return your CF but it might not be correct value. For a better solution you need to return a single MetricName in your card visual.

_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn | Follow on Medium
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.

I'm not quite sure I follow. I'm assuming you are saying placing the MetricName in the Categories field for a card isn't the same as placing MetricName in the Rows field (ie it doesn't reduce the context), but I guess I'm finding that counter intuitive considering you end up with something approximately visually equivalent in my toy example. But more importantly, does that mean there's no way for the DAX to leverage the Categories field for conditional formatting? It seems like a logical use case might be to show a series of cards of sales per country and color each card differently. It seems not workable to have to create one card per country since you wouldn't necessarily know up front which countries might be in the data. And it seems like that's what the new card is trying to solve for.

FBergamaschi
Super User
Super User

Hi @schwartzaw 

SELECTEDVALUE returns a value only when there is only one value.

 

IN a matrix, it works if you group the Metric[MetricName], in a card you cannot. So you should filter one value for that column. If you show me what you are doing in detail, I can be more precise

 

Best

 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

Consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

Here's an image of what I'm trying to accomplish. You can see with the matrix that the DAX works as expected, coloring each row appropriately but does not work for the new card (which it colors both yellow). It may be a misunderstanding on my part, but I'm unclear why SELECTEDVALUE() works in the matrix as I'd expect but not in a card.

 

screenshot.png

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.