Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by watching the DP-600 session on-demand now through April 28th.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
Hello,
I am planning to get the count for the previous day
Date ID
9/1/2020 A1001
9/1/2020 B1001
9/1/2020 C1001
9/1/2020 D1001
9/1/2020 E1001
9/2/2020 A1001
9/2/2020 B1001
9/2/2020 C1001
9/2/2020 D1001
9/2/2020 E1001
9/2/2020 F1001
9/4/2020 B1001
9/4/2020 C1001
9/4/2020 D1001
9/5/2020 C1001
9/5/2020 D1001
9/5/2020 E1001
9/5/2020 F1001
9/5/2020 F1001
I created a measure DayCount = Calculate(CountA(MainAccount[ID]),userelationship(Date[date], MainAccount[Date])), which gives me.
Date DayCount
9/1/2020 5
9/2/2020 6
9/4/2020 3
9/5/2020 5
The goal is to achieve the below.
| Date | DayCount | Change |
| 9/5/2020 | 5 | +2 |
| 9/4/2020 | 3 | -3 |
| 9/2/2020 | 6 | +1 |
| 9/1/2020 | 5 | 0 |
I thought of using ealier function to get the previous value and then do a difference of the two columns to get the Change and hide the "Ealier" column. But my earlier function is incorrect.
DayPreviousCount = Countrows(Filter(MainAccount, earlier(MainAccount[date]) >= MainAccount[date]))
Any help on how to achieve this value please.
Solved! Go to Solution.
Hi @PBI5851 ,
You can create a measure as below:
Count difference =
var _previouscount=CALCULATE(COUNT('Table'[ID]),FILTER(ALL('Table'),'Table'[Date]=MAXX(FILTER(ALL('Table'),'Table'[Date]<MAX('Table'[Date])),'Table'[Date])))
var _count=CALCULATE(COUNT('Table'[ID]),FILTER(ALL('Table'),'Table'[Date]=MAX('Table'[Date])))
Return
IF(_previouscount=BLANK(),0,_count-_previouscount)
And you will see:
Or you can create a calculated column as below:
_Countdifference =
var _previousdate=MAXX(FILTER('Table','Table'[Date]<EARLIER('Table'[Date])),'Table'[Date])
var _previouscount=CALCULATE(COUNT('Table'[ID]),FILTER('Table','Table'[Date]=_previousdate))
var _count=CALCULATE(COUNT('Table'[ID]),FILTER('Table','Table'[Date]=EARLIER('Table'[Date])))
Return
IF(_previouscount=BLANK(),0,_count-_previouscount)
And you will see:
For the related .pbix file,pls see attached.
Hi @PBI5851 ,
You can create a measure as below:
Count difference =
var _previouscount=CALCULATE(COUNT('Table'[ID]),FILTER(ALL('Table'),'Table'[Date]=MAXX(FILTER(ALL('Table'),'Table'[Date]<MAX('Table'[Date])),'Table'[Date])))
var _count=CALCULATE(COUNT('Table'[ID]),FILTER(ALL('Table'),'Table'[Date]=MAX('Table'[Date])))
Return
IF(_previouscount=BLANK(),0,_count-_previouscount)
And you will see:
Or you can create a calculated column as below:
_Countdifference =
var _previousdate=MAXX(FILTER('Table','Table'[Date]<EARLIER('Table'[Date])),'Table'[Date])
var _previouscount=CALCULATE(COUNT('Table'[ID]),FILTER('Table','Table'[Date]=_previousdate))
var _count=CALCULATE(COUNT('Table'[ID]),FILTER('Table','Table'[Date]=EARLIER('Table'[Date])))
Return
IF(_previouscount=BLANK(),0,_count-_previouscount)
And you will see:
For the related .pbix file,pls see attached.
@PBI5851 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
@PBI5851 , Create a date table and try like one of the following examples
Day behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Day))
Diff COlumn = datediff(maxx(filter('Table','Table'[Date]<earlier('Table'[Date]) && 'Table'[Numberf]= earlier('Table'[Numberf]) ),'Table'[Date]) ,'Table'[Date],Day)
This Day = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Date]=max('Date'[Date])))
Last Day = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Date]=max('Date'[Date])-1))
Last Day = CALCULATE(sum('order'[Qty]), previousday('Date'[Date]))
Last Day Non Continuous = CALCULATE([sales],filter(ALLSELECTED('Date'),'Date'[Date] =MAXX(FILTER(ALLSELECTED('Date'),'Date'[Date]<max('Date'[Date])),'Date'[Date])))
Refer
Check out the April 2026 Power BI update to learn about new features.
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 |
|---|---|
| 43 | |
| 37 | |
| 35 | |
| 22 | |
| 15 |
| User | Count |
|---|---|
| 65 | |
| 58 | |
| 29 | |
| 27 | |
| 25 |