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
jopezzo
Helper I
Helper I

How to filter a table based on a column's highest value

Hi,

 

I am trying to calculate the total quantity by Quality from a table called "Data", but filtering on the highest value in Period (in this case, 201906).  The purpose is to calculate the variance for each quality (highest period/lowest period).

 

In other words, I would like to get for each product Quantity [Period 201906] / Quantity [Period 201902]

 

DAX Max value.jpg

Source file

 

I have tried different formulas but I'm struggling with the filter context.

 

Can anyone help me?

 

Thanks!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Please use the same link as above.

Best
D.

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Again, please resist the temptation to do it in DAX. Use Power Query because this is the right tool for the job.

Best
D.

How would you proceed, then, with Query M?

Anonymous
Not applicable

Thanks @Anonymous  and @Greg  for your solutions. My description of the issue is probably not accurate enough. What I am looking for is not retrieving the minimum quantity for each quantity. I want to retrieve the quantity for the Maximum value in "Period".

 

So for Quality "A", I want to retrieve the quantity where the value "Period" is the highest, so 10, not 13.

 

Then I would like to do the same for the minimum Period (so retrieve Quantity 5 for Quality A in @Anonymous 's example).

 

In the end, I would divide the Quantity for the highest Period by the Quantity for the lowest Period, for each Quality. That would give me an index, which is the scope of all the above.

 

I thought that DAX was the right language to solve this question but I didn't figure out how, despite may trials.

 

Thanks again for your help!

Anonymous
Not applicable

Please use the same link as above.

Best
D.
Anonymous
Not applicable

OK. So you need another table (created in PQ) that for each quality will store the quantities for the latest and oldest period.

 

I'll post a link to a file shortly.

Best
Dare

Yes, I think that should be a way to go. 🙂

Greg_Deckler
Super User
Super User

Create a DAX formula that goes something like this:

 

Measure IsHighest = 
  VAR __table = SUMMARIZE(ALLSELECTED('Table'),[Quality], [Period],"__Quantity",SUM([Quantity]))
  VAR __max = MAXX(__table,[__Quantity])
  VAR __period = MAXX(FILTER(__table,[__Quantity] = __max),[Period])
RETURN
  IF(MAX([Period]) = __period,1,0)

Then just fiilter on this being 1


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.

Top Solution Authors