Forum Discussion

bestevezdyb's avatar
bestevezdyb
Frequent Visitor
2 years ago
Solved

DAX SelectedValue With If

Good morning,

I would like to understand how to solve a problem that apparently is getting complicated. I have created a metric that is

NumberOfPizza =
VAR _qty = COUNTROWS( order_details )
RETURN
IF( _qty = BLANK(), 0, _qty)


And the next measure is 
​
SelectedValue =
SELECTEDVALUE( order_details[pizza_id] )

The result is as follow

 

 

How can I get the pizza type value to appear as a metric in the 0?

Thank you in advance
  • bestevezdyb's avatar
    bestevezdyb
    2 years ago

    I think I have the solution

    SelectedValue =
     
    VAR _qty = [NumberOfPizza]
    RETURN
    IF(
        _qty = 0,
        CALCULATE(MAX(order_details[pizza_id]), REMOVEFILTERS(DimDate)),  -- Devuelve el valor de pizza_id si _qty es 0
        SELECTEDVALUE( order_details[pizza_id] )
    )

3 Replies

  • hi bestevezdyb ,

     

    not sure if i really get you, try like:

    SelectedValue = SELECTEDVALUE( order_details[pizza_id], 0 )

    • bestevezdyb's avatar
      bestevezdyb
      Frequent Visitor

      I think I have the solution

      SelectedValue =
       
      VAR _qty = [NumberOfPizza]
      RETURN
      IF(
          _qty = 0,
          CALCULATE(MAX(order_details[pizza_id]), REMOVEFILTERS(DimDate)),  -- Devuelve el valor de pizza_id si _qty es 0
          SELECTEDVALUE( order_details[pizza_id] )
      )