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.
Hello guys,
I have a table and a slicer like the following:
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!
Solved! Go to 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 ) )
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 ) )
For more details, please check the pbix as attached.
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 ) )
@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.
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.
yeah, No measures involved
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!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
107 | |
93 | |
77 | |
65 | |
53 |
User | Count |
---|---|
147 | |
106 | |
104 | |
87 | |
61 |