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,
I'm trying to calculate daily increments of a value for each ID and timestamp. This is my as-is situation sample:
ID | timestamp | value |
key01 | 20191101 | 150 |
key01 | 20191031 | 135 |
key01 | 20191030 | 100 |
key02 | 20191101 | 8 |
key02 | 20191031 | 6 |
key03 | 20191101 | 1450 |
What I want to achieve is adding a calculated column, which would store the increment of value from previous day (based on timestamp)
So I would like to get something like this:
ID | timestamp | value | increment |
key01 | 20191101 | 150 | 15 |
key01 | 20191031 | 135 | 35 |
key01 | 20191030 | 100 | null |
key02 | 20191101 | 8 | 2 |
key02 | 20191031 | 6 | null |
key03 | 20191101 | 1450 | null |
Thanks for your advice in advance!
Regards,
Pavel
Solved! Go to Solution.
Hi @Anonymous
Try something like this.
Column =
VAR __timeStamp = 'Table'[timestamp]
VAR __previousDate =
CALCULATE(
MAX( 'Table'[timestamp] ),
ALLEXCEPT( 'Table', 'Table'[ID] ),
'Table'[timestamp] < __timeStamp
)
VAR __previousValue =
CALCULATE(
SUM( 'Table'[value] ),
TREATAS( { __previousDate }, 'Table'[timestamp] ),
ALLEXCEPT( 'Table', 'Table'[ID] )
)
RETURN IF( __previousValue > 0, 'Table'[value] - __previousValue )
Column =
VAR _date = Test[timestamp]
VAR _prevdate = CALCULATE(MAX(Test[timestamp]),FILTER(ALLEXCEPT(Test,Test[ID]),Test[timestamp]<_date))
VAR _prevValue = CALCULATE(SUM(Test[value]),FILTER(ALLEXCEPT(Test,Test[ID]),Test[timestamp]=_prevdate))
RETURN IF(_prevdate<>BLANK(),Test[value]-_prevValue)
@Anonymous
Hi @Anonymous
Try something like this.
Column =
VAR __timeStamp = 'Table'[timestamp]
VAR __previousDate =
CALCULATE(
MAX( 'Table'[timestamp] ),
ALLEXCEPT( 'Table', 'Table'[ID] ),
'Table'[timestamp] < __timeStamp
)
VAR __previousValue =
CALCULATE(
SUM( 'Table'[value] ),
TREATAS( { __previousDate }, 'Table'[timestamp] ),
ALLEXCEPT( 'Table', 'Table'[ID] )
)
RETURN IF( __previousValue > 0, 'Table'[value] - __previousValue )
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
23 | |
8 | |
7 | |
6 | |
6 |
User | Count |
---|---|
28 | |
12 | |
10 | |
10 | |
6 |