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.

Frequent Visitor

## Find the first date that hits the goal

I am trying to find the first date that hits the goal (100 in this case) per ID

Below is the sample data structure and desired output

What would be the DAX Formula for calculating the "First Date to hit the goal"?

1 ACCEPTED SOLUTION
Super User

@kangx322  if you have a table (called 'fact')  like this

``````| id | date       | value |
|----|------------|-------|
| 1  | 2021-01-01 | 20    |
| 1  | 2021-01-01 | 30    |
| 1  | 2021-01-02 | 70    |
| 1  | 2021-01-02 | 40    |
| 1  | 2021-01-03 | 80    |
| 1  | 2021-01-03 | 90    |
| 2  | 2021-01-01 | 80    |
| 2  | 2021-01-02 | 40    |
| 2  | 2021-01-03 | 70    |
| 2  | 2021-01-03 | 60    |
| 2  | 2021-01-04 | 130   |``````

and desire to come to this

You can write following two measures

``````earliestDayTargetMet =
CALCULATE (
MIN ( 'fact'[date] ),
FILTER (
'fact',
'fact'[date]
= CALCULATE (
MINX (
FILTER (
'fact',
"sum",
CALCULATE (
SUM ( 'fact'[value] ),
ALLEXCEPT ( 'fact', 'fact'[id], 'fact'[date] )
)
),
[sum] >= 100
),
'fact'[date]
),
ALLEXCEPT ( 'fact', 'fact'[id] )
)
)
)

sumValueOnEarliestDayTargetMet =
CALCULATE (
SUM ( 'fact'[value] ),
FILTER (
'fact',
'fact'[date]
= CALCULATE (
MINX (
FILTER (
'fact',
"sum",
CALCULATE (
SUM ( 'fact'[value] ),
ALLEXCEPT ( 'fact', 'fact'[id], 'fact'[date] )
)
),
[sum] >= 100
),
'fact'[date]
),
ALLEXCEPT ( 'fact', 'fact'[id] )
)
)
)``````

Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
4 REPLIES 4
Community Champion

Excel worksheet formulae are power enough to handle it with ease.

 Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! DAX is simple, but NOT EASY!
Community Champion

 Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! DAX is simple, but NOT EASY!
Anonymous
Not applicable

Hello @CNENFRNL .
I had the exact same problem, with the same kind of table/columns, and your solution worked fine for me.
The only difference is that the Target is set to 100 (fixed) and not Max(Target[target])
The problem is that i want the earliest date as a column, in order to use it as a filter or in the x-axis of a line chart.
When i use your DAX in a calculated column i get the following error message "a circular dependency was detected".

The exact DAX i use for the calculated column is the following:

earliest_date_correct_column =
var tgt=100
return
minx(
filter(
values(Sales[date]),
CALCULATE(sum(Sales[value]), Sales[date]<= earlier ( Sales[date]))>= tgt),
Sales[date])

Kostas
Super User

@kangx322  if you have a table (called 'fact')  like this

``````| id | date       | value |
|----|------------|-------|
| 1  | 2021-01-01 | 20    |
| 1  | 2021-01-01 | 30    |
| 1  | 2021-01-02 | 70    |
| 1  | 2021-01-02 | 40    |
| 1  | 2021-01-03 | 80    |
| 1  | 2021-01-03 | 90    |
| 2  | 2021-01-01 | 80    |
| 2  | 2021-01-02 | 40    |
| 2  | 2021-01-03 | 70    |
| 2  | 2021-01-03 | 60    |
| 2  | 2021-01-04 | 130   |``````

and desire to come to this

You can write following two measures

``````earliestDayTargetMet =
CALCULATE (
MIN ( 'fact'[date] ),
FILTER (
'fact',
'fact'[date]
= CALCULATE (
MINX (
FILTER (
'fact',
"sum",
CALCULATE (
SUM ( 'fact'[value] ),
ALLEXCEPT ( 'fact', 'fact'[id], 'fact'[date] )
)
),
[sum] >= 100
),
'fact'[date]
),
ALLEXCEPT ( 'fact', 'fact'[id] )
)
)
)

sumValueOnEarliestDayTargetMet =
CALCULATE (
SUM ( 'fact'[value] ),
FILTER (
'fact',
'fact'[date]
= CALCULATE (
MINX (
FILTER (
'fact',
"sum",
CALCULATE (
SUM ( 'fact'[value] ),
ALLEXCEPT ( 'fact', 'fact'[id], 'fact'[date] )
)
),
[sum] >= 100
),
'fact'[date]
),
ALLEXCEPT ( 'fact', 'fact'[id] )
)
)
)``````

Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

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