15 Replies Latest reply: Dec 4, 2017 9:17 AM by Sunny Talwar RSS

    FirstSortedValue

    Juan Moreno

      Hi all,

       

      I have a database with events, each of them with certain properties (status, etc.) and duration.

       

      I want to display the event that matches some properties and has the longest duration without exceeding a limit. I've written the following expression:

       

      FirstSortedValue({1<is_planned_event={"0"},event_status_id={"22"}, event_duration={"<200"}>} event_duration,-event_duration, 1)

       

      Nothing is shown. Why?

       

      On a table, I've been able to display an event with is_planned_event={"0"},event_status_id={"22"} and event_duration=17. So there's definitely something in my DB that should be shown. Do you see any mistake in the expression?


      Thanks,


      Juan

        • Re: FirstSortedValue
          Sunny Talwar

          Why do you need FirstSortedValue() function here... may be you need Max()?

           

          Max({1<is_planned_event={"0"},event_status_id={"22"}, event_duration={"<200"}>} event_duration)

            • Re: FirstSortedValue
              Juan Moreno

              Actually Min, yes, that would work. But I have to display next to it the second element that meet the conditions, and then the third, and so on. That's why I need the FirstSortedValue() function.

                • Re: FirstSortedValue
                  Sunny Talwar

                  Not sure I follow this... can you share an example?

                    • Re: FirstSortedValue
                      Juan Moreno

                      Sorry Sunny, my bad. You're right about the "Max". But the reason to use FirstSortedValue is that I want to show more than one event.

                       

                      I have several "gauge" elements on my dashboard, using the following expressions:

                       

                      FirstSortedValue({1<is_planned_event={"0"},event_status_id={"22"}, event_duration={"<200"}>} event_duration,-event_duration, 1)

                      FirstSortedValue({1<is_planned_event={"0"},event_status_id={"22"}, event_duration={"<200"}>} event_duration,-event_duration, 2)

                      FirstSortedValue({1<is_planned_event={"0"},event_status_id={"22"}, event_duration={"<200"}>} event_duration,-event_duration, 3)

                      FirstSortedValue({1<is_planned_event={"0"},event_status_id={"22"}, event_duration={"<200"}>} event_duration,-event_duration, 4)

                      FirstSortedValue({1<is_planned_event={"0"},event_status_id={"22"}, event_duration={"<200"}>} event_duration,-event_duration, 5)

                       

                      The objective is to show the 5 events with the longest duration, but that don't exceed the limit (200).

                       

                      Thanks,

                       

                      Juan

                • Re: FirstSortedValue
                  Andrea Gigliotti

                  maybe there are more event_duration sharing the same value.