Forum Discussion
Filtered min function
- 9 years ago
Hi mikaro,
According to your description, you should be able to follow steps below to get your expected result.
I assume you have a table called "Table1" like below.
1. Add an Index Column in Query Editor.
2. Use the formula below to create a calculate column to get the first negative date from current row for each row.
FirstNegativeDate = VAR i = Table1[Index] RETURN IF ( Table1[Value] < 0, BLANK (), CALCULATE ( MIN ( Table1[Date] ), FILTER ( ALL ( Table1 ), Table1[Index] > i && Table1[Value] < 0 ) ) )3. Then you should be able to calculate the difference between the positive transaction and the first negative transaction from current row.
DateDifference = IF ( Table1[FirstNegativeDate] <> BLANK (), DATEDIFF ( Table1[Date], Table1[FirstNegativeDate], DAY ) )Here is the sample pbix file for your reference.:smileyhappy:
Regards
Hi mikaro,
According to your description, you should be able to follow steps below to get your expected result.
I assume you have a table called "Table1" like below.
1. Add an Index Column in Query Editor.
2. Use the formula below to create a calculate column to get the first negative date from current row for each row.
FirstNegativeDate =
VAR i = Table1[Index]
RETURN
IF (
Table1[Value] < 0,
BLANK (),
CALCULATE (
MIN ( Table1[Date] ),
FILTER ( ALL ( Table1 ), Table1[Index] > i && Table1[Value] < 0 )
)
)
3. Then you should be able to calculate the difference between the positive transaction and the first negative transaction from current row.
DateDifference =
IF (
Table1[FirstNegativeDate] <> BLANK (),
DATEDIFF ( Table1[Date], Table1[FirstNegativeDate], DAY )
)
Here is the sample pbix file for your reference.:smileyhappy:
Regards
Thank you v-ljerr-msft your solution was exactly what i was trying to achieve! Didn't know that you could write functions with variables like that in Power BI :smileyvery-happy: