Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
NaderSaeed
Helper II
Helper II

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

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @NaderSaeed ,

According to your description, here’s my solution.

vkalyjmsft_0-1637040035263.png

 

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.

View solution in original post

7 REPLIES 7
v-yanjiang-msft
Community Support
Community Support

Hi @NaderSaeed ,

According to your description, here’s my solution.

vkalyjmsft_0-1637040035263.png

 

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.

@v-yanjiang-msft 

 

Genius ! Thank you so much! ❤️

Greg_Deckler
Super User
Super User

@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)
  

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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'

NaderSaeed_0-1636818981141.png

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.

@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)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hello @Greg_Deckler 

 

I really appreciate your time trying to help me out.

I tried your last formula, and unfortuantly it didn't give the expected results as well.

I'm sure it's due to my bad explanation.

NaderSaeed_0-1636908936765.png

 

Let me attempt this one last time:

 

- If [Duration] in 'Table 1' falls between two values of the [Duration] in 'Table 2'. (for each Name and Level)

- to return 1, The [Index] in 'Table 1' associated with that Duration must be >= the [Index] in 'Table 2' assocaited with Minimum [Index] of the two values that the [Duration] is falling in between of.

 

Example:

- If Table 1 Duration is 2.7, then the Index has to be >= 60 to return 1, else it should be zero.
- Also if duration is < 2 it should return 0, because this duration less than the Min for that level in 'Table 2'

 

'Table 2'

LevelDurationIndex
3260
3340



I know I confused you enough here, I'm sorry 🙂 

@NaderSaeed Post your sample data for Table1 and Table2 as text and I'll construct a working example. 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.