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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
hadi2002
Frequent Visitor

Get latest date based on filtered column

Hi All, I have a dt which contain a 'Date' & 'Status' column. I just want to get the most latest date amoung those records which has 'Status'='Success' & 'Exception'. Once get the latest date, I need to count how many minutes diffrent from current time.

I tried below query, but I'm getting this error "A single value for column 'ActionDate' in table 'cndn_main' cannot be determined."

Queue = CALCULATE
(
MAX('main'[Date], FILTER('main', main[Status] IN { "Success", "Exception" }))
)
Can anyone help me to guide this please? Am I writing anything wrong?
1 ACCEPTED SOLUTION

@hadi2002 ,

 

Sorry, can you let me know what is the expected output.

 

You can put a filter on "Success" .

 

Also, just change "Postponed" to "Exception"

 

Queue =

CALCULATE
(
MAX(Table6[TimeString]), FILTER(ALL('Table6'),Table6[Status] ="Success" || Table6[Status] = "EXception" )
)

 

 

 

 

 

 

Date DIff = var a = DATEDIFF(MAXX(ALL(Table6),Table6[TimeString]),[Queue],MINUTE)

RETURN
a
 
 
1.jpg
 
 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

View solution in original post

11 REPLIES 11
harshnathani
Community Champion
Community Champion

@hadi2002 ,

 

Try adding ALL in Filter.

 

Queue = CALCULATE
(
MAX('main'[Date], FILTER(ALL('main'), main[Status] IN { "Success", "Exception" }))
)
 
Queue = CALCULATE
(
MAX('main'[Date], FILTER(ALL('main'), main[Status] ="Success" || main[Status] = "Exception" ))
)
 
Please share some sample data to help you better.
 
Regards,
Harsh Nathani

Hi @harshnathani , thanks alot. That works but gaves me this error.

 

A single value for column 'ActionDate' in table 'cndn_main' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

 

 

This is how data look like? Could you please help me on this.

 

Capture.PNG

@hadi2002 ,

 

Syntax Error:

 

Queue = CALCULATE
(
MAX('main'[Date]), FILTER(ALL('main'), main[Status] ="Success" || main[Status] = "Exception" ))
)
 
 
Missed the bracket after MAX.
 
Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)
 

@hadi2002 ,

 

 

Suppose you have the below Table6

 

1.jpg

 

Use the measures

 

Queue = CALCULATE
(
MAX(Table6[TimeString]), FILTER(ALL('Table6'),Table6[Status] ="Success" || Table6[Status] = "Postponed" )
)
 
Date DIff = DATEDIFF(MAX(Table6[TimeString]),[Queue],MINUTE)
 
2.JPG
 
 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Hi @harshnathani 

Thanks for you help. But I just wants the most lowest one datediff which has 'Success' & 'Exception' status (ignore postponed) only shown in the card. 😞

 

2.JPG

@hadi2002 ,

 

Sorry, can you let me know what is the expected output.

 

You can put a filter on "Success" .

 

Also, just change "Postponed" to "Exception"

 

Queue =

CALCULATE
(
MAX(Table6[TimeString]), FILTER(ALL('Table6'),Table6[Status] ="Success" || Table6[Status] = "EXception" )
)

 

 

 

 

 

 

Date DIff = var a = DATEDIFF(MAXX(ALL(Table6),Table6[TimeString]),[Queue],MINUTE)

RETURN
a
 
 
1.jpg
 
 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

hi @harshnathani 

Thanks alot for your help, that really work perfect as what was expected. However, I'm stuck at another last part. Hope you can help me on this to group the data. For example, let's say I have a table as below which shows a column called as Robot and ActionDate (as shown in first picture). 

Capture.PNG

I just wants to group the robot column and populate the max date for each respective robots and shows me what is the diffrence from the time now. 

Capture2.PNG

Your help would be highly appreciated

Hi @hadi2002 
 
 
Time Difference1 =
VAR _a =
CALCULATE( MAX ( 'Table'[Date/Time] ), ALLEXCEPT('Table','Table'[robot]))
RETURN
DATEDIFF (
 
_a,TODAY(),
DAY
)
 
Max_Date/Time = CALCULATE(MAX('Table'[Date/Time]), ALLEXCEPT('Table','Table'[robot]))
 
 
Pull Robot, Max_Date/Time and Time Difference1 in a table.
 
Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Hi @harshnathani 

But the result is showing all the data. Is it possible for that particlar measure to return only - list of robots which are having date diff which is less than 30 mins only? Please 

Hi @hadi2002 ,

 

 

Measure 2 =

Var _dd = DATEDIFF(MAX('Table'[Date/Time]),NOW(),MINUTE)
REturn
//_dd
CALCULATE(COUNT('Table'[Robot]), FILTER('Table', _dd < 30))
 
1.jpg
 
 
2.JPG
 
 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

 

@hadi2002 ,

 

You can also use

 

Time Difference1 =
VAR _a =
CALCULATE( MAX ( 'Table'[Date/Time] ), ALLEXCEPT('Table','Table'[robot]))
RETURN
DATEDIFF (
 
_a,NOW(),
MINUTE
)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.