Forum Discussion

volt26's avatar
volt26
Icon for Helper I rankHelper I
1 year ago
Solved

DAX formula that returns columns based on subcolumn's value from smallest to highest

Hello!

 

I need to return columns but the data needed varies on a subcolumn named KEY. Each EVENT can have multiple KEY entries. If KEY is the lowest of EVENT, the formula needs to take the data from column START. If KEY is the highest of EVENT, it needs to take the data from column END. For erverything else, it needs to take the data from MIDDLE.

 

To help figure out what's needed, I summarized things with this Excel table : 

 

If we look at EVENT entry 'C'

The desired result should somehow calculate this : 

lowest KEY of EVENT = 35
highest KEY of EVENT = 26
everything else = 14 + 67
Desired result is = 35+26+14+67=142

In other words, I think the right formula would be something like :
START of lowestKEY + ( SUM of MIDDLE for all keys then substracts MIDDLE of lowestKEY and also substract MIDDLE of highestKEY ) + END of highestKEY
=> 
35 + ( (76+14+67+5)-(76+5) ) + 26

I'm not quite familiar with DAX but I learn here and there with tutorials. I couldn't find answers for this specific issue. Thanks for your time!

7 Replies

    • volt26's avatar
      volt26
      Icon for Helper I rankHelper I

      Wow that is very impressive!

       

      Unfortunately, I get this error in my real file : 

       

      It works well when I select one single EVENT but when I select multiple ones, it doesn't.

       

      The demo file provided doesn't return the SUM of all the EVENTS either.

       

      Do you think it is possible to add this feature? I've never been closer to my goal before you gave me this!

       

      I wonder if the formula has to be in the table instead of in a measure?

  • Hi,

    Share data in a format that can be pasted in an MS Excel file.

    • volt26's avatar
      volt26
      Icon for Helper I rankHelper I

      Here it is : 

       

      EVENTKEYSTARTMIDDLEEND
      A150618
      A2233141
      A3451813
      B172654
      B291790
      C1357643
      C281421
      C3666798
      C485526

       

      It will most likely be possible to copy-paste it. 🙂