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

Find LatestResult dynamically: Measure showing too many values

Hello everyone,

I have a problem with my table. I want to be able to show only the latest result based on the version. The version always changes depending on my visual filter. The LastModified is a real column in my dataset and the LatestResult is a measure to calculate the latest result dynamically. So far so good. The table looks somewhat like the following:

IDVersionResultLastModifiedLatestResult
123.5Pass23.11.202125.11.2021
123.6Failed25.11.202125.11.2021
223.5Pass23.11.202123.11.2021
323.5Pass23.11.202130.11.2021
323.6Pass25.11.202130.11.2021
324Pass30.11.202130.11.2021
423.7Failed27.11.2021

27.11.2021

Now I need to change that LatestResult measure so it gives TRUE/FALSE or 0/1,  IF(LastModified = LatestResult).

The measure looks like this:

LatestResult =
var MaxDate = CALCULATE(MAXX(RESULT,[LASTMODIFIED]),
ALLSELECTED([Version],[RESULT],[LASTMODIFIED]))

return MaxDate
 
I thought about doing this to get both Max and current date and then comparing it to be able to filter after >1 to get latest result:
LatestResult =
var MaxDate = CALCULATE(MAXX(RESULT,[LASTMODIFIED]),
ALLSELECTED([Version],[RESULT],[LASTMODIFIED]))

var currentDate = CALCULATE(MAXX(RESULT,[LASTMODIFIED]),
ALLSELECTED([LASTMODIFIED]))

return IF(MaxDate = currentDate, 0,1)
 
But somehow this than gives me like way over 1000 rows in the table instead of the few results that are actually there.
What am I missing, why is it giving me more rows than there should be? Am I missing any context or filters to be applied?
Or how can I achieve to get a dynamic measure filter like this to show only latest result?
 
P.S: I cant use calculated columns or any PowerQuery because its only for visual level use and will always change
depending on the selection that the user makes.

Found someone with almost the same problem:
Dax - IF statement comparing two measures 
1 ACCEPTED SOLUTION

@Anonymous , Try a new measure or a new column

 

measure =
var _1 = calculate(Lastnonblankvalue(Table[LastModified], max(Table[Version])), filter(allselected(Table), Table[ID] = max(Table[ID])))
return
if( max(Table[Version]) =_1, true(), false())

 

 

new column =
var _1 = maxx(filter(Table, [ID] = earlier([ID]) ), [LastModified])
var _2 = maxx(filter(Table, [ID] = earlier([ID]) && LastModified] = _1 ), [Version])
return
if( (Table[Version]) =_2, true(), false())

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , Try a measure like

 

measure =
var _1 = calculate(Lastnonblankvalue(Table[LastModified], max(Table[Version])), filter(allselected(Table), Table[ID] = max(Table[ID])))
return
calculate(Max(Table[Result]), filter( allselected(Table), Table[ID] = max(Table[ID]) && Table[Version] =_1))

Anonymous
Not applicable

@amitchandak  Thanks for your reply.

This measure is now returning the Result for every ID. But I want to have an indicator like TRUE/FALSE or 0/1 if it is the last result or not. So your measure gives me results like this:

IDVersionResultLastModifiedLatestResultmeasure
123.5Pass23.11.202125.11.2021Failed
123.6Failed25.11.202125.11.2021Failed
223.5Pass23.11.202123.11.2021Pass
323.5Pass23.11.202130.11.2021Pass
323.6Pass25.11.202130.11.2021Pass
324Pass30.11.202130.11.2021Pass
423.7Failed27.11.2021

27.11.2021

Failed

 

What I want to achieve is something like this:

IDVersionResultLastModifiedLatestResultmeasure
123.5Pass23.11.202125.11.2021False
123.6Failed25.11.202125.11.2021True
223.5Pass23.11.202123.11.2021True
323.5Pass23.11.202130.11.2021False
323.6Pass25.11.202130.11.2021False
324Pass30.11.202130.11.2021True
423.7Failed27.11.2021

27.11.2021

True

 

If I could achieve this, than I could filter after only TRUE and get only latest result dynamically.

Any idea how to do that? Thanks @amitchandak 

@Anonymous , Try a new measure or a new column

 

measure =
var _1 = calculate(Lastnonblankvalue(Table[LastModified], max(Table[Version])), filter(allselected(Table), Table[ID] = max(Table[ID])))
return
if( max(Table[Version]) =_1, true(), false())

 

 

new column =
var _1 = maxx(filter(Table, [ID] = earlier([ID]) ), [LastModified])
var _2 = maxx(filter(Table, [ID] = earlier([ID]) && LastModified] = _1 ), [Version])
return
if( (Table[Version]) =_2, true(), false())

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.