cancel
Showing results 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.

Regular Visitor

## Time between two dates based on criteria

Hello!

I have a table of ticket data where I for each critical ticket need to calculate the time since the last critical ticket was registered.
Been trying to solve this for a few hours now without success.

Basically: If Priority = Critical, calculate time between regdate and previous critical tickets' regdate (for each row). The goal is to calculate the average time between critical tickets being registered.

Any help would be greatly apreciated!

5 REPLIES 5
Super User

Hi Jowh,

here comes the code for the calculated column:
Duration =
VAR CurrentDate = 'Table'[Date]
VAR TABLE1 =
CALCULATETABLE(
'TABLE',
FILTER ('Table', 'Table'[Priority]="Yes"),
FILTER ('Table', 'Table'[Date]>CurrentDate)
)
VAR MinDate =
MINX (
TABLE1,
'Table'[Date]-CurrentDate)
RETURN
IF (
'Table'[Priority]="Yes",
INT( MinDate)
)
Regular Visitor

Hello and thank you!

It is something similar but in the reverse order I suppose. Latest date should show the previous max date with Priority if that makes sense. Also presented in hours or minutes but I think I could figure that part out myself in worst case 🙂

Super User

Good Luck!

Regular Visitor

Not really getting this to work 😞 Tried to change to the following:

``````Time Since Last Critical =
VAR CurrentDate = Issues[DATE_CREATED]
VAR TABLE1 =
CALCULATETABLE(
'Issues',
FILTER ('Issues', 'Issues'[ISSUE_PRIORITY]="Critical"),
FILTER ('Issues', 'Issues'[DATE_CREATED]<CurrentDate)
)
VAR MinDate =
MAXX(
Issues,
Issues[DATE_CREATED]-CurrentDate)
RETURN
IF (
Issues[ISSUE_PRIORITY]="Critical",
INT( MinDate),blank()
)``````

I don't really understand the MinDate logic though (tried both MINX and MAXX)

Super User

The first argument of MINX shall be the filtered table - Table1, instead of the native table - Issues.

MINX is to scan Table1 and get the immediate last date tagged "Critical."

Announcements

#### 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

#### Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

#### Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors