Forum Discussion
topazz11
Helper III
8 months agodaily variance in DAX
How do I calculate the variance as below? ---i tried to write it and doesnt work. Daily Variance = VAR _maxvalue = CALCULATE ( MAX ( table[Value] ), FILTER ( table, table[Date] ...
- 8 months ago
topazz11 I think that the following should work:
Daily Variance = VAR _CurrentDate = MAX( 'Table'[Date] ) VAR _PreviousDate = CALCULATE( MAX( 'Table'[Date] ), 'Table'[Date] = _CurrentDate - 1 ) VAR _CurrentValue = MAX( 'Table'[Value] ) VAR _PreviousValue = CALCULATE( MAX( 'Table'[Value] ), 'Table'[Date] = _PreviousDate ) VAR _Return = IF( _PreviousDate = BLANK(), 0, _CurrentValue - _PreviousValue ) RETURN _Return
phpimran
8 months agoNew Member
I think this can be easily handled using DATEADD function. Below is the code I have used in my sample dataset to calculate variance vs previous day:
Daily_Variance =
VAR CurrentValue = SUM(DailyVar[Daily Value])
VAR PreviousValue =
CALCULATE(
SUM(
DailyVar[Daily Value]
),
DATEADD(
DailyVar[Order Date],
-1,
DAY
)
)
RETURN
CurrentValue - PreviousValue
My sample data set
| Order Date | Daily Value |
| 12/10/2025 | 178 |
| 12/11/2025 | 192 |
| 12/12/2025 | 102 |
| 12/13/2025 | 182 |
| 12/14/2025 | 109 |
| 12/15/2025 | 187 |
| 12/16/2025 | 155 |
| 12/17/2025 | 119 |
| 12/18/2025 | 172 |
| 12/19/2025 | 120 |
Power BI result set:
I hope this helps.
Thanks.