Forum Discussion

Username1848's avatar
Username1848
Frequent Visitor
2 years ago
Solved

Return result based on if statement: Error "Single value can't be determined"

Hello,

I have a table called “Data”. This table has the three columns “Customer”, “Metric” and “Value”.

  • “Customer” contains customer names in text.
  • “Metric” contains the metric names in text
  • “Value” contains the result of the customer and metric combination in that specific line.

The same customers appear once for each characteristic of “Metric”. The “Data” table looks like this:

Customer  Metric   Value
AMetric 1     3
AMetric 2     2
AMetric 3     1
BMetric 1     2
BMetric 2     3
BMetric 3     2
CMetric 1     1
CMetric 2     2
CMetric 3     3
DMetric 1     2
DMetric 2     1
DMetric 3     3
EMetric 1     1
EMetric 2     1
EMetric 3     2
FMetric 1     3
FMetric 2     2
FMetric 3     2

 

I want to write a measure in DAX that checks for the number in “Value” for the metric in “Metric” and performs a specific action based on the combination of metric and value. I tried it with the following measure:

Measure =

IF(‘Data’[Metric] = “Metric 1” &&  “Data”[Value]=3, “Top score”,

IF(‘Data’[Metric] = “Metric 1” &&  “Data”[Value]=2, “Mid score”,

IF(‘Data’[Metric] = “Metric 1” &&  “Data”[Value]=1, “Low score”)

 

I would create this measure for each existing metric.

At the end I want to select one customer and show the results of the IF statement (Metric 1 = Top score, Metric 2 = Low Score, …) in a format I have not yet decided on, probably in a table.

When I write this measure in PowerBI I get the error:

“A single value for column 'Metric' in table 'Data’ cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.”

 

I assume that this is because the metrics in “Metric” appear once for each customer. I tried to figure this out with other ways like CALCULATETABLE, SUMX, and so on, but I couldn’t get it to work.

 

Can you help me formulating a measure that can do what I want to?

Any help is appreciated!

  • Arul's avatar
    Arul
    2 years ago

    Username1848 ,

    try this in calculated column,

    Score Distribution = 
    SWITCH(
        TRUE(),
        'Table'[Metric] ="Metric 1" && 'Table'[Value] =3 ,"Top Score",
        'Table'[Metric] ="Metric 1" && 'Table'[Value] =2 ,"Mid Score",
        'Table'[Metric] ="Metric 1" && 'Table'[Value] =1 ,"Low Score",
        'Table'[Metric] ="Metric 2" && 'Table'[Value] =3 ,"Top Score",
        'Table'[Metric] ="Metric 2" && 'Table'[Value] =2 ,"Mid Score",
        'Table'[Metric] ="Metric 2" && 'Table'[Value] =1 ,"Low Score",
        'Table'[Metric] ="Metric 3" && 'Table'[Value] =3 ,"Top Score",
        'Table'[Metric] ="Metric 3" && 'Table'[Value] =2 ,"Mid Score",
        'Table'[Metric] ="Metric 3" && 'Table'[Value] =1 ,"Low Score")

    I have attached the file for reference. 

3 Replies

    • Username1848's avatar
      Username1848
      Frequent Visitor

      Hello, thank you for your reply.

       

      Whatever works to show the result of the IF statement evaluation. 

       

      At the end I want to select one customer with a slicer or filter and display the results of only this customer in a table or text field, whatever will work.

      • Arul's avatar
        Arul
        Super User

        Username1848 ,

        try this in calculated column,

        Score Distribution = 
        SWITCH(
            TRUE(),
            'Table'[Metric] ="Metric 1" && 'Table'[Value] =3 ,"Top Score",
            'Table'[Metric] ="Metric 1" && 'Table'[Value] =2 ,"Mid Score",
            'Table'[Metric] ="Metric 1" && 'Table'[Value] =1 ,"Low Score",
            'Table'[Metric] ="Metric 2" && 'Table'[Value] =3 ,"Top Score",
            'Table'[Metric] ="Metric 2" && 'Table'[Value] =2 ,"Mid Score",
            'Table'[Metric] ="Metric 2" && 'Table'[Value] =1 ,"Low Score",
            'Table'[Metric] ="Metric 3" && 'Table'[Value] =3 ,"Top Score",
            'Table'[Metric] ="Metric 3" && 'Table'[Value] =2 ,"Mid Score",
            'Table'[Metric] ="Metric 3" && 'Table'[Value] =1 ,"Low Score")

        I have attached the file for reference.