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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Gav10
Helper II
Helper II

Return previous month value based on ID

Hi

 

This is driving me insane!

 

I have a table full of ID's with values for particular dates. I would like to create a new column which returns the previous value for each ID, but only if it is the previous month.

 

The dates are all the first date in the month. The example of what i would like to return is below

 

Untitled.jpg

I've tried all sorts of code, none of which i can get to work!

 

Any help is greatly appreciated

 

1 ACCEPTED SOLUTION

@Gav10 , My mistake , it should me maxx

 

Previous value =

var _min = maxx(filter(Table,[ID] = earlier([ID]) && [Date] < earlier([Date]) ),[Date])
return
maxx(filter(Table,[ID] = earlier([ID]) && [Date] =_min),[Current Value])

View solution in original post

5 REPLIES 5
latimeria
Solution Specialist
Solution Specialist

@Gav10 ,

If this can help

Previous value = 
VAR CurrentID = 'Previous Row DAX'[ID]
VAR PreviousMonth_1 =
    PREVIOUSMONTH ( 'Previous Row DAX'[Date] )
VAR PreviousValue =
    CALCULATE (
        MAX ( 'Previous Row DAX'[Current value] ),
        REMOVEFILTERS ('Previous Row DAX'),
        CurrentID = 'Previous Row DAX'[ID],
        PreviousMonth_1 = 'Previous Row DAX'[Date]
    )
RETURN
    PreviousValue

 

latimeria_0-1666962920748.png

 

amitchandak
Super User
Super User

@Gav10 , Create a new column

Previous value =

var _min = minx(filter(Table,[ID] = earlier([ID]) && [Date] < earlier([Date]) ),[Date])
return
maxx(filter(Table,[ID] = earlier([ID]) && [Date] =_min),[Current Value])

 

Power BI DAX- Earlier, I should have known Earlier: https://youtu.be/CVW6YwvHHi8

Thanks but this doesn't work i'm afraid. It returns the value if it has changed over the time period and not what it was the previous month. See below

 

Untitled.png

@Gav10 , My mistake , it should me maxx

 

Previous value =

var _min = maxx(filter(Table,[ID] = earlier([ID]) && [Date] < earlier([Date]) ),[Date])
return
maxx(filter(Table,[ID] = earlier([ID]) && [Date] =_min),[Current Value])

So unfortunately this still doesn't return the desired result.

 

It's finding the previous instance regardless of the date. I only want it to look at the previous month. So for September it should be showing blank and not 1 as there is no record of the ID in August

 

Untitled.jpg

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.