Forum Discussion

Sjoerd_g's avatar
Sjoerd_g
Frequent Visitor
3 years ago
Solved

Using SELECTEDVALUE with SUMMARIZE

Hi all,

 

I have a dilemma as I'm trying to create a visual that is seemingly very straightforward but I have tried several approaches, and nothing is what I'd like although I got quite close.

 

I have a table with ratings, which has several ratings per response id and for each the score for this rating:

I'd like to test this data and know the Average score when the Food score is below 2, and like it to look similar to this graph created in Excel:

I knew I couldn't just simply set up a Clustered Column Chart and filter the ratings when Food is 1 or 2, because this obviously only impacts the Food rating:

 

So I figured summarize table could help here, but since we're not working in the main dataset and are connected to a dataset, I can't add a table. Therefore I went for a measure:

 

 

Atmosphere when Food is 1 or 2 = 
AVERAGEX(
    FILTER(
        SUMMARIZE(
            ALLSELECTED(ratings),
            [response id],
            "Atmosphere", CALCULATE(AVERAGE(ratings[score]),SEARCH("Atmosphere", ratings[Translated Rating],,0)),
            "Cleanliness", CALCULATE(AVERAGE(ratings[score]),SEARCH("Cleanliness", ratings[Translated Rating],,0)),
            "Drink", CALCULATE(AVERAGE(ratings[score]),SEARCH("Drink", ratings[Translated Rating],,0)),
            "Food", CALCULATE(AVERAGE(ratings[score]),SEARCH("Food", ratings[Translated Rating],,0)),
            "Service", CALCULATE(AVERAGE(ratings[score]),SEARCH("Service", ratings[Translated Rating],,0)),
            "Value", CALCULATE(AVERAGE(ratings[score]),SEARCH("Value", ratings[Translated Rating],,0))
        ),
        [Food] <= 2
    ),
    [Atmosphere]
)

 

The above creates a table with all the responses and a column for each rating, and then it filters this when the Food rating is equal to or below 2 and returns the Average rating for one of the columns. Bingo! That gave me the correct result, so I created a measure for each column.

 

I then simply added those measures to a Clustered Column Chart, and I have a visual showing the correct figures:

BUT, this comes in this ridiculous layout where every column is lumped together, and I can't add the [Rating] column to the X-axis because that just duplicates all the data:

I thought maybe if the measure could just pick up the SELECTEDVALUE of the Rating column, it could solve this issue, or is there a different way to test this data that I am missing?

 

Thanks for your help.

  • I managed to solve this and thought it might be useful for anyone else.

     

    I set up Variables with the initially mentioned measure and used the SWITCH combined with SELECTEDVALUE to test if the name matched and returned the correct VAR.

     

    RETURN
    SWITCH(
        TRUE(),
        SELECTEDVALUE(ratings[rating]) = "Atmosphere", _atmosphere,
        SELECTEDVALUE(ratings[rating]) = "Cleanliness", _Cleanliness,
        SELECTEDVALUE(ratings[rating]) = "Drink", _Drink,
        SELECTEDVALUE(ratings[rating]) = "Service", _Service,
        SELECTEDVALUE(ratings[rating]) = "Value", _Value
    )

     

    VAR example: 

    VAR _Value = 
    AVERAGEX(
        FILTER(
            SUMMARIZE(
                ALLSELECTED(ratings),
                [response id],
                "Atmosphere", CALCULATE(AVERAGE(ratings[score]),SEARCH("Atmosphere", ratings[Translated Rating],,0)),
                "Cleanliness", CALCULATE(AVERAGE(ratings[score]),SEARCH("Cleanliness", ratings[Translated Rating],,0)),
                "Drink", CALCULATE(AVERAGE(ratings[score]),SEARCH("Drink", ratings[Translated Rating],,0)),
                "Food", CALCULATE(AVERAGE(ratings[score]),SEARCH("Food", ratings[Translated Rating],,0)),
                "Service", CALCULATE(AVERAGE(ratings[score]),SEARCH("Service", ratings[Translated Rating],,0)),
                "Value", CALCULATE(AVERAGE(ratings[score]),SEARCH("Value", ratings[Translated Rating],,0))
            ),
            [Food] <= 2
        ),
        [Value]
    )

     

3 Replies

    • Sjoerd_g's avatar
      Sjoerd_g
      Frequent Visitor

      How exactly do you mean?

       

      This would just duplicate the one-column average:

      AVERAGEX(
          FILTER(
              SUMMARIZE(
                  ALLSELECTED(ratings),
                  [response id],
                  "Atmosphere", CALCULATE(AVERAGE(ratings[score]),SEARCH("Atmosphere", ratings[Translated Rating],,0)),
                  "Cleanliness", CALCULATE(AVERAGE(ratings[score]),SEARCH("Cleanliness", ratings[Translated Rating],,0)),
                  "Drink", CALCULATE(AVERAGE(ratings[score]),SEARCH("Drink", ratings[Translated Rating],,0)),
                  "Food", CALCULATE(AVERAGE(ratings[score]),SEARCH("Food", ratings[Translated Rating],,0)),
                  "Service", CALCULATE(AVERAGE(ratings[score]),SEARCH("Service", ratings[Translated Rating],,0)),
                  "Value", CALCULATE(AVERAGE(ratings[score]),SEARCH("Value", ratings[Translated Rating],,0))
              ),
              [Food] <= 2
          ),
          [Cleanliness]
      )

       

      And when I remove the Averagex part:

          FILTER(
              SUMMARIZE(
                  ALLSELECTED(ratings),
                  [response id],
                  "Atmosphere", CALCULATE(AVERAGE(ratings[score]),SEARCH("Atmosphere", ratings[Translated Rating],,0)),
                  "Cleanliness", CALCULATE(AVERAGE(ratings[score]),SEARCH("Cleanliness", ratings[Translated Rating],,0)),
                  "Drink", CALCULATE(AVERAGE(ratings[score]),SEARCH("Drink", ratings[Translated Rating],,0)),
                  "Food", CALCULATE(AVERAGE(ratings[score]),SEARCH("Food", ratings[Translated Rating],,0)),
                  "Service", CALCULATE(AVERAGE(ratings[score]),SEARCH("Service", ratings[Translated Rating],,0)),
                  "Value", CALCULATE(AVERAGE(ratings[score]),SEARCH("Value", ratings[Translated Rating],,0))
              ),
              [Food] <= 2
          )

      We get a measure returning multiple values, resulting in the following error:

       

  • Sjoerd_g's avatar
    Sjoerd_g
    Frequent Visitor

    I managed to solve this and thought it might be useful for anyone else.

     

    I set up Variables with the initially mentioned measure and used the SWITCH combined with SELECTEDVALUE to test if the name matched and returned the correct VAR.

     

    RETURN
    SWITCH(
        TRUE(),
        SELECTEDVALUE(ratings[rating]) = "Atmosphere", _atmosphere,
        SELECTEDVALUE(ratings[rating]) = "Cleanliness", _Cleanliness,
        SELECTEDVALUE(ratings[rating]) = "Drink", _Drink,
        SELECTEDVALUE(ratings[rating]) = "Service", _Service,
        SELECTEDVALUE(ratings[rating]) = "Value", _Value
    )

     

    VAR example: 

    VAR _Value = 
    AVERAGEX(
        FILTER(
            SUMMARIZE(
                ALLSELECTED(ratings),
                [response id],
                "Atmosphere", CALCULATE(AVERAGE(ratings[score]),SEARCH("Atmosphere", ratings[Translated Rating],,0)),
                "Cleanliness", CALCULATE(AVERAGE(ratings[score]),SEARCH("Cleanliness", ratings[Translated Rating],,0)),
                "Drink", CALCULATE(AVERAGE(ratings[score]),SEARCH("Drink", ratings[Translated Rating],,0)),
                "Food", CALCULATE(AVERAGE(ratings[score]),SEARCH("Food", ratings[Translated Rating],,0)),
                "Service", CALCULATE(AVERAGE(ratings[score]),SEARCH("Service", ratings[Translated Rating],,0)),
                "Value", CALCULATE(AVERAGE(ratings[score]),SEARCH("Value", ratings[Translated Rating],,0))
            ),
            [Food] <= 2
        ),
        [Value]
    )