Forum Discussion

NaderSaeed's avatar
NaderSaeed
Icon for Helper II rankHelper II
4 years ago
Solved

Calculated Column based on multiple Min & MAX conditions

Hello, 

 

Need help to write a conditoonal column for 'Table 1'.

 

To check each Name's Level in 'Table 2' and applies the following logic:

 

If the Duration in 'Table 1' falls between 2 values for that Level's Duration in 'Table 2', 'Table 1'[Index] has to ALSO be >= 'Table 2'[Index] associated with the smaller value of the that 'Table 2'[Duraion].

 

For example:

 

For Joe below, His Index in 'Table 1' is "38", I want the calculated column to return "1" If, and only if, the Duration in 'Table 1' is >= 4.75.

 

In the case below, Joe's duration is 4.7, which is < 4.75 (i.e. the Duration in Table 2 associated with Index 38)

 

'Table 1'

NameLevelDurationIndex
Adam34.1544
Joe44.738
Sam11.815
Gerard2423
Jamie44.2556
Bane1312
Mike3530


'Table 2'

LevelDuration Index
11.522
1210
2339
23.533
2427
24.515
3456
34.2550
34.544
34.7538
3532
35.2526
35.520
4456
44.2544
44.542
44.7538
4532
45.2526
45.520


Expected Results:

NameLevelDurationIndexExpected
Adam34.15440
Joe44.7380
Sam11.8150
Gerard24230
Jamie44.25561
Bane13101
Mike35300
     

 

Thank You

  • Hi NaderSaeed ,

    According to your description, here’s my solution.

     

    Best Regards,
    Community Support Team _ kalyj

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

7 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    NaderSaeed Perhaps:

     

    Expected =
      VAR __Duration = 'Table 1'[Duration]
      VAR __Index = 'Table 1'[Index]
      VAR __Level = 'Table 1'[Level]
      VAR __Table2Duration = MAXX(FILTER('Table 2',[Index]=__Index && [Level]=__Level),[Duration])
    RETURN
      IF(__Duration >= __Table2Duration,1,0)
      

     

    • NaderSaeed's avatar
      NaderSaeed
      Icon for Helper II rankHelper II

      Hello Greg_Deckler  

       

      Thank you for attempting this.

       

      I found that all the "0"s are 100% correct with my data set.

      However, I found that some of the "1"s are not accurate.


      For example, When I applied your calculated column on the in the example in the post. 
      I get the below:

       

      NameLevelDurationIndexExpected
      Adam34.15440
      Joe44.7380
      Sam11.8150
      Gerard24230
      Jamie44.25560
      Bane13121
      Mike35300

       

      Jamie's expected column is giving 0 and it shoud be 1.

       

      Because Jamie's Duration is 4.25, so according to Table 2, he's got to have an Index of 44 or higher to return "1" and he's got 56, so it should be 1.

      'Table 2'

      I'm also getting some "1"s where the Duration in 'Table 1' is smaller than the smallest value for Duration in 'Table 2' per level.

      • Greg_Deckler's avatar
        Greg_Deckler
        Icon for Community Champion rankCommunity Champion

        NaderSaeed Oh, I was misunderstanding and had Duration and Index mixed around, try:

        Expected =
          VAR __Duration = 'Table 1'[Duration]
          VAR __Index = 'Table 1'[Index]
          VAR __Level = 'Table 1'[Level]
          VAR __Table2Index = MAXX(FILTER('Table 2',[Duration]=__Duration && [Level]=__Level),[Index])
        RETURN
          IF(__Index >= __Table2Index,1,0)
  • Hi NaderSaeed ,

    According to your description, here’s my solution.

     

    Best Regards,
    Community Support Team _ kalyj

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.