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
lulubyte
New Member

Create Measure and Dynamically Return MAX Value from Filtered Rows with DAX

I am trying to create a measure to return the maximum TimeId grouped by the ScenarioId illustrated in the table below.

 

Users can filter this table with a slicer on the ActualValue column to return only the rows that meet a certain threshold. From there I need to find the maximum TimeId by ScenarioId so I can use that measure to filter another table.

 

This cannot be precalculated as the user will be able to filter which rows they see.

 

Is something like this possible? I've been trying for a few hours but cannot get anything to work. I could do this in SQL in a few seconds with a subquery, but we need users to be able to filter ad-hoc.

 

ScenarioIdUnitIdTimeIdActualValue
1A110
1A415
1B15
1C510
2A215
2A620
2B310
2B515
1 ACCEPTED SOLUTION

@lulubyte 

Below measure should do the work. This will work when some value is selected in the slicer.

Max_timeid = CALCULATE(max('Table'[TimeId]),ALLEXCEPT('Table','Table'[ScenarioId],'Table'[ActualValue]))

NaveenGandhi_0-1685922232871.png

Let me know if this helps!

If this post helps, then please consider Accept it as the solution to help the others find it more quickly. Appreciate you kudos!!

View solution in original post

6 REPLIES 6
lulubyte
New Member

Thanks for the reply.

 

For some reason the ALLEXCEPT seems to disregard the slicer to filter the TargetValue column. The ALLEXCEPT returns the maximum TimeId, but it doesn't apply it to the rows filtered from the slicer...

 

 

@lulubyte 

Can you share the sample data and expected output? So that it will be easy to understand the problem.

Sure, if a user selected the value 15 in the ActualValue slicer then the following data would be returned if the ScenarioId and TimeId columns were placed into a table visual:

 

ScenarioIdTimeId
14
25

 

The way I would think of this as a workflow would be:

 

  1. The ActualValue slicer first filters the table to show only rows where the ActualValue column is equal to 15.
  2. Then the measure would find the maximum TimeId from those rows.

@lulubyte 

Below measure should do the work. This will work when some value is selected in the slicer.

Max_timeid = CALCULATE(max('Table'[TimeId]),ALLEXCEPT('Table','Table'[ScenarioId],'Table'[ActualValue]))

NaveenGandhi_0-1685922232871.png

Let me know if this helps!

If this post helps, then please consider Accept it as the solution to help the others find it more quickly. Appreciate you kudos!!

That did the trick! Thank you so much for your help, it has saved me quite a bit of time!

NaveenGandhi
Super User
Super User

Hello @lulubyte 

 

Try this Measure. 

Max_timeid = CALCULATE(max('Table'[TimeId]),ALLEXCEPT('Table','Table'[ScenarioId]))

Let me know if this helps!

If this post helps, then please consider Accept it as the solution to help the others find it more quickly. Appreciate you kudos!!

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.