We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hi,
I'm trying to work out how to use a measure to caclualte the datedifference between rows
I've got an dataset that looks like (Date formatting is DD/MM/YYYY)
| ID | StartDate |
| 1 | 13/08/2017 |
| 2 | 13/08/2017 |
| 3 | 12/08/2017 |
| 4 | 24/08/2017 |
So far, I've added the following Measure using RANKX
RankMeasure = RANKX(
ALLSELECTED(TABLE),
CALCULATE(
FIRSTDATE(TABLE[StartDate])),,ASC,Dense)
When i add this to a table visualisation i get the follow
| ID | StartDate | RankMeasure |
| 1 | 13/08/2017 | 2 |
| 2 | 13/08/2017 | 2 |
| 3 | 12/08/2017 | 1 |
| 4 | 24/08/2017 | 3 |
So far so good, Now i'm trying to calculate the DateDifference (in days) between the rows so the result should look like
| ID | StartDate | RankMeasure | DateDifference (days) |
| 1 | 13/08/2017 | 2 | 1 |
| 2 | 13/08/2017 | 2 | 1 |
| 3 | 12/08/2017 | 1 | 0 |
| 4 | 24/08/2017 | 3 | 11 |
Any help would be great.
Thanks
Solved! Go to Solution.
Hey everyone, thanks for your help,
I managed to do it using the following measure (turns out, I don't need the rank column)
DaysBetweenFaults =
var currentDate = SELECTEDVALUE(Table[StartDate])
var previousDate = CALCULATE(
Max(Table[StartDate]),
ALLSELECTED(Table),
Table[StartDate] < currentDate)
return
if(not ISBLANK(DATEDIFF(previousDate,currentDate,DAY)),DATEDIFF(previousDate,currentDate,DAY),0)
Hey everyone, thanks for your help,
I managed to do it using the following measure (turns out, I don't need the rank column)
DaysBetweenFaults =
var currentDate = SELECTEDVALUE(Table[StartDate])
var previousDate = CALCULATE(
Max(Table[StartDate]),
ALLSELECTED(Table),
Table[StartDate] < currentDate)
return
if(not ISBLANK(DATEDIFF(previousDate,currentDate,DAY)),DATEDIFF(previousDate,currentDate,DAY),0)
Hi @Tapemeasure
I create a Calculated Column to rank StartDate:
Rank = RANKX('Table','Table'[StartDate],,ASC,Dense)And I build a Day column:
Day = DAY('Table'[StartDate])Then I use a measure to achieve your goal:
DateDifference (days) =
IF(MAX('Table'[Rank])=1,
0,
MAX('Table'[Day])-CALCULATE(VALUES('Table'[Day]),FILTER(ALL('Table'),'Table'[Rank]=MAX('Table'[Rank])-1)))Result:
You can download the pbix file form this link:
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@Tapemeasure , If IS/Rank are continous
new column = datediff(Table[Date], maxx(filter(Table,Table[ID] =earlier(Table[ID])-1) ,Table[Date]),day)
// non-continous
new column 2 =
var _ min = maxx(filter(Table,Table[ID] < earlier(Table[ID])-1) ,Table[ID])
return
datediff(Table[Date], minx(filter(Table,Table[ID] =_min) ,Table[Date]),day)
Both Measure and column methods is disuccsed here too
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 56 | |
| 40 | |
| 35 | |
| 18 | |
| 18 |
| User | Count |
|---|---|
| 69 | |
| 64 | |
| 38 | |
| 34 | |
| 23 |