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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Help with the Dax Expression.

Hello guys,

 

I have a table and a slicer like the following:

tttf final.PNG

I'm looking to write an DAX expression for the following logic :

 

I need to find the Maximum value of the Diff column corresponding to the "n"th distinct assignment number where "n" is the minimum value of the "req total pos" column. Another filter would be just the value "Keep".

 

In this example - after I select 9 in the slicer - I need to get - "15" since it corresponds to the second distinct assignment number.

 

Logic=

Min value in the "req total pos" column = "2"

so the "2" nd distinct value of the ass number = "901"

Max value of the Diff column of that assignment number(901)  is "15"

 

Looking forward to your help.

 

Thanks,

Anand!

 

 

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Update the formula as below.

Measure 2 =
VAR maxp =
    MAX ( 'Table'[req total pos] )
VAR kk =
    TOPN (
        maxp,
        FILTER ( 'Table', 'Table'[Elim or keep] <> "Elim" ),
        'Table'[Ass Number], ASC
    )
VAR c =
    CALCULATE ( MAX ( 'Table'[Ass Number] ), KEEPFILTERS ( kk ) )
RETURN
    CALCULATE ( MAX ( 'Table'[Diff] ), FILTER ( 'Table', 'Table'[Ass Number] = c ) )

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

9 REPLIES 9
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can create a measure as below.

Measure 2 = 
VAR maxp =
    MAX ( 'Table'[req total pos] )
VAR kk =
    TOPN ( maxp, 'Table', 'Table'[Ass Number], ASC )
VAR c =
    CALCULATE ( MAX ( 'Table'[Ass Number] ), KEEPFILTERS ( kk ) )
RETURN
    CALCULATE ( MAX ( 'Table'[Diff] ), FILTER ( 'Table', 'Table'[Ass Number] = c ) )

 

Capture.PNG

 

For more details, please check the pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

Thanks for the response and it works great! But as I had mentioned, I should also filter out the rows with "Elim". Where do I include that filter in your code?

 

Hi @Anonymous ,

 

Update the formula as below.

Measure 2 =
VAR maxp =
    MAX ( 'Table'[req total pos] )
VAR kk =
    TOPN (
        maxp,
        FILTER ( 'Table', 'Table'[Elim or keep] <> "Elim" ),
        'Table'[Ass Number], ASC
    )
VAR c =
    CALCULATE ( MAX ( 'Table'[Ass Number] ), KEEPFILTERS ( kk ) )
RETURN
    CALCULATE ( MAX ( 'Table'[Diff] ), FILTER ( 'Table', 'Table'[Ass Number] = c ) )

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
parry2k
Super User
Super User

@Anonymous Even you explained it very well but I'm still not sure how you get to value 15 based on your example. Can you put the example in excel sheet with couple of examples to understand it correctly so that we can provide you the solution.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Thank you for your response.

Let me explain the "15" -

 

I get 4 rows after selecting "9" from the slicer

 

Then I filter rows with just values "Keep" - I get 3 rows now.

 

Then I would look for the Min value in the Req total pos column - which will give me "2"

 

Let's keep "n=2"

 

Then I would look for the "nth" distinct assignment number which is 901(2nd distinct value). [1st distinct value = 900, 2nd distinct value = 901]

 

Then I would look for the max value in the Diff column correspondig to "901"

 

Hence it would be "15"

 

Hope this helps!

 

@Anonymous got it, all these are column in your dataset or there are calculated measure. Just want to make sure I understood the dataset correctly.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@Anonymous it helps, so basically there is no calculated Measure



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

yeah, No measures involved

Anonymous
Not applicable

Thanks for your response.

 

Elim or Keep , Req total pos , Diff -- these three columns are calculated columns.

 

Other three columns are from dataset.

Hope this helps

 

 

Thanks!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.