Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Date | COUNT(ID) |
01/01/2023 | 15000 |
05/02/2023 | 15100 |
07/02/2023 | 15030 |
08/02/2023 | 18000 |
17/03/2023 | 14500 |
Hello there,
I use direct query, how can I calculate change between days without any logical chronology between each day?
I just want to calculate the change with the previous row.
Thanks in advance,
Solved! Go to Solution.
Thanks a lot for your help @barritown. I found the right code :
AMeasure Difference =
VAR CurrentCount = CALCULATE(COUNT(products[id]))
VAR CurrentDate = LASTDATE(products[date])
VAR PreviousDate = MAXX(FILTER(ALL(products), products[date] < CurrentDate ), products[date])
VAR PreviousCount = CALCULATE(COUNT(products[id]), FILTER(ALL(products), products[date] = PreviousDate))
RETURN IF(ISBLANK(PreviousCount), BLANK(), CurrentCount - PreviousCount)
This looks like OK for me 🙂
Hello @barritown, thanks a lot for your help.
Your purpose doesn't work because COUNT(ID) is a calculated measure already (Measure COUNT(ID) = Count(products[ID])
I've tried to set a column for this count but it doesn't work too.
AMeasure Difference =
VAR CurrentCount = MAX(COUNT(products[id]))
VAR CurrentDate = MAX(products[date])
VAR PreviousDate = MAXX(FILTER(ALL(products), [date] < CurrentDate ),[date])
VAR PreviousCount = MAXX(FILTER(ALL(products), [date] = PreviousDate ), (COUNT(products[id])))
RETURN IF(ISBLANK(PreviousCount), BLANK(), CurrentCount - PreviousCount)
Error : The MAX function in DAX only accepts a column reference as an argument
Hello @Anonymous,
For me it's difficult to take another try w/o access to your data model. If you can create a PBIX containing it and some toy data and share it with me, I'll be able to try to adapt my solution for your model.
Thanks a lot for your help @barritown. I found the right code :
AMeasure Difference =
VAR CurrentCount = CALCULATE(COUNT(products[id]))
VAR CurrentDate = LASTDATE(products[date])
VAR PreviousDate = MAXX(FILTER(ALL(products), products[date] < CurrentDate ), products[date])
VAR PreviousCount = CALCULATE(COUNT(products[id]), FILTER(ALL(products), products[date] = PreviousDate))
RETURN IF(ISBLANK(PreviousCount), BLANK(), CurrentCount - PreviousCount)
This looks like OK for me 🙂
Hi @Anonymous,
If entries in your table are sorted by date and there are no duplicate dates, you could try such a measure:
In plain text for convenience:
Difference Measure =
VAR CurrentCount = MAX ( [COUNT(ID)] )
VAR CurrentDate = MAX ( [Date] )
VAR PreviousDate = MAXX ( FILTER ( ALL ( data ), [Date] < CurrentDate ), [Date] )
VAR PreviousCount = MAXX ( FILTER ( ALL ( data ), [Date] = PreviousDate ), [COUNT(ID)] )
RETURN IF ( ISBLANK ( PreviousCount ), BLANK(), CurrentCount - PreviousCount )
Best Regards,
Alexander
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
14 | |
11 | |
10 | |
10 | |
10 |
User | Count |
---|---|
18 | |
13 | |
12 | |
11 | |
8 |