Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Previous value measures not working as expected

Hi Experts

 

Based on the sample data in the PBIX...

I cannot get my previous value calculate column measure to work and return the expected result as shown in the image below

BlueWhite111_0-1669230499216.png

 

 

Measure

Current Row = RANKX( ALL('Table'), 'Table'[month], , ASC, Dense)
Previous Row = 
VAR CurrentRow = 'Table'[Current Row]
VAR PreviousRow = CALCULATE(
    MAX('Table'[Current Row]), 
    ALL('Table'),
    'Table'[family] = EARLIER('Table'[family]),
    'Table'[DDate] < EARLIER('Table'[DDate])
)
RETURN IF( PreviousRow <> BLANK(), PreviousRow, CurrentRow )
Previous Quantity = 
CALCULATE(
    MAX('Table'[qty]), 
    ALL('Table'), 
    'Table'[family] = EARLIER('Table'[family]), 
    'Table'[Current Row] = EARLIER('Table'[Previous Row])
) 

 sampledata 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , if you need a new column

 

previous Qty =
var _max = maxx(filter(Table, Table[family] = earlier([Family]) && [Date] < earlier([Date])), [Date])
return
maxx(filter(Table, Table[family] = earlier([Family]) && [Date] =_max ), [qty])

 

For measure join date with the date table and try TI

 

examples

 

last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))
MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

 

Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
https://www.youtube.com/watch?v=6LUBbvcxtKA

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@Anonymous , if you need a new column

 

previous Qty =
var _max = maxx(filter(Table, Table[family] = earlier([Family]) && [Date] < earlier([Date])), [Date])
return
maxx(filter(Table, Table[family] = earlier([Family]) && [Date] =_max ), [qty])

 

For measure join date with the date table and try TI

 

examples

 

last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))
MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

 

Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
https://www.youtube.com/watch?v=6LUBbvcxtKA

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors