Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi guys,
I'm trying to calculate the interval of days between a date value and the last date before that date (doing this to all dates in column), and then show the max value of these intervals.
For example:
1. calculate the date intervals between the dates on column:
2. and then return the max value from the intervals calculated above (6 days), in a measure.
Some idea?
Appreciate any help.
Solved! Go to Solution.
Hi,
Please check the below picture and the attached pbix file.
I added two more rows in the sample in order to check if it works correctly.
Expected result measure: =
VAR newtable =
ADDCOLUMNS (
Data,
"@previous",
CALCULATE (
CALCULATE (
MAX ( Data[DataRef] ),
FILTER (
ALL ( Data ),
Data[DataRef] < VAR currentdataref = MAX ( Data[DataRef] ) RETURN currentdataref
)
)
)
)
VAR intervaltable =
FILTER (
ADDCOLUMNS ( newtable, "@interval", INT ( Data[DataRef] - [@previous] ) ),
[@previous] <> BLANK ()
)
VAR maximuminterval =
MAXX ( intervaltable, [@interval] )
RETURN
maximuminterval
Hi,
Please check the below picture and the attached pbix file.
I added two more rows in the sample in order to check if it works correctly.
Expected result measure: =
VAR newtable =
ADDCOLUMNS (
Data,
"@previous",
CALCULATE (
CALCULATE (
MAX ( Data[DataRef] ),
FILTER (
ALL ( Data ),
Data[DataRef] < VAR currentdataref = MAX ( Data[DataRef] ) RETURN currentdataref
)
)
)
)
VAR intervaltable =
FILTER (
ADDCOLUMNS ( newtable, "@interval", INT ( Data[DataRef] - [@previous] ) ),
[@previous] <> BLANK ()
)
VAR maximuminterval =
MAXX ( intervaltable, [@interval] )
RETURN
maximuminterval
Thanks! It worked for me.
@filipeoliveira , A new column
datediff([Dateref], minx(filter(Table, [Dateref] >earlier([Dateref]) ), [DateRef]) , Day)
or
datediff([Dateref], maxx(filter(Table, [Dateref] <earlier([Dateref]) ), [DateRef]) , Day)
User | Count |
---|---|
25 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
30 | |
13 | |
11 | |
9 | |
6 |