Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!View all the Fabric Data Days sessions on demand. View schedule
Hello PBI Community! Hope you are doing all right! 🙂
I need some assistance to calculate the difference between values of a same column; this is for a social media database, and the measure I had working just fine it's simply not anymore.
The data is appended everyday for different accounts, which here are represented by A, B and C, and the dates are from the column date.
The problem is that I need to calculate and show the amount of new followers acquired between two dates (usually a full month, but it needs to be flexible), and the data is not always organized by date and/or product:
For example, I'd need to calculate the difference between may 17th and 18th for name A, that is
88961-88889, but the values are separated by other values:
| date | name | total_followers |
| 18/05/2023 | A | 88961 |
| 18/05/2023 | B | 2882 |
| 18/05/2023 | C | 1935 |
| 17/05/2023 | A | 88889 |
| 17/05/2023 | B | 2868 |
| 17/05/2023 | C | 1935 |
| 16/05/2023 | A | 88793 |
| 16/05/2023 | B | 2858 |
| 16/05/2023 | C | 1937 |
| 15/05/2023 | A | 88710 |
| 15/05/2023 | B | 2848 |
| 15/05/2023 | C | 1936 |
| 14/05/2023 | A | 88674 |
| 14/05/2023 | B | 2847 |
| 14/05/2023 | C | 1937 |
| 13/05/2023 | A | 88674 |
| 13/05/2023 | B | 2847 |
| 13/05/2023 | C | 1937 |
| 12/05/2023 | A | 88580 |
| 12/05/2023 | B | 2832 |
| 12/05/2023 | C | 1935 |
| 11/05/2023 | A | 88514 |
| 11/05/2023 | B | 2794 |
| 11/05/2023 | C | 1929 |
| 10/05/2023 | A | 88459 |
| 10/05/2023 | B | 2784 |
| 10/05/2023 | C | 1924 |
| 09/05/2023 | A | 88373 |
| 09/05/2023 | B | 2766 |
Also, I'm currently using this Dax Formula to do the math, but it's not working (showing 0):
this firstdate() and lastdate() are supposed to get the dates from a date slicer, using a calendar table:
Measure =
VAR _FollowersOnLastDate =
CALCULATE(
MAX( Table[total_followers] ) ,
FILTER( Table ,
AND( Table[name] = SELECTEDVALUE( 'Table _ Media'[produto] ) ,
DATEADD ( FILTER ( DATESMTD ( d_Calendar[Date]), d_Calendar[Date] < TODAY()), -1, MONTH)) +0
)
)
)
VAR _FollowersOnFirstDate =
CALCULATE(
MAX( Table[total_followers] ) ,
FILTER( Table ,
AND( Table[name] = SELECTEDVALUE( 'Table _ Media'[produto] ) ,
DATEADD ( FILTER ( DATESMTD ( d_Calendar[Date]), d_Calendar[Date] < TODAY()), -1, MONTH)) +0
)
)
)
VAR _MinFollowers =
CALCULATE(
MIN( Table[total_followers] ) ,
FILTER( Table ,
Table[name] = SELECTEDVALUE( 'Table _ Media'[produto] )
)
)
-------------------------------------------------------
RETURN _FollowersOnLastDate - _FollowersOnFirstDate
SWITCH(
TRUE() ,
LASTDATE( d_Calendar[Date] ) <= MIN( Table[date] ) , 0 ,
FIRSTDATE( d_Calendar[Date] ) < MIN( Table[date] ) , _FollowersOnLastDate - _MinFollowers ,
_FollowersOnLastDate - _FollowersOnFirstDate
) +0
Any suggestions on how to improve this code, or to do the calculation as per I explained above?
Thanks once again for the assistance, in advance! 🙂
Best Regards,
@talitanieps See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column =
VAR __Current = [Value]
VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])
VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
__Current - __Previous
Hello @Greg_Deckler ,
Thanks a lot for your reply!
I'll review that and let you know of the results, thanks again! 🙂
Best regards,
Talita.
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!