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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
gchn
Frequent Visitor

Measure to get previous value with same attributes

I have a table with multiple attribute/category columns (call them A1, A2, ...), a date column and a value column.

I've been trying for too long to get a measure that gives me the value for the previously available date, given that all attribute are the same.

Example:
date              A1  A2 .... value   new_measure
06/30/2023   a    c            1      BLANK

06/30/2023   b    d           2      BLANK

07/03/2023   a    c            3      1

07/04/2023   a    c           4      3

07/03/2023   a    d           5      BLANK

07/04/2023   a    d          6       5


How can I do it?

6 REPLIES 6
gchn
Frequent Visitor

Nothing of the above worked. I ended up using an actually useful tool (a Python script) to do that before feeding it into Power BI. I guess it's my fault for thinking a Microsoft product would work.

Anonymous
Not applicable

HI @gchn,

Here is the dax measure formula and sample file about get the previous value based on use current date and multiple attribute field values:

formula =
VAR currDate =
    MAX ( 'Table'[date] )
VAR prevDate =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER ( ALLSELECTED ( 'Table' ), [date] < currDate ),
        VALUES ( 'Table'[A1] ),
        VALUES ( 'Table'[A2] )
    )
RETURN
    IF (
        prevDate <> BLANK (),
        CALCULATE (
            SUM ( 'Table'[value] ),
            FILTER ( ALLSELECTED ( 'Table' ), [date] = prevDate ),
            VALUES ( 'Table'[A1] ),
            VALUES ( 'Table'[A2] )
        )
    )

1.png
Regards,

Xiaoxin Sheng

Anonymous
Not applicable

Hi @gchn ,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information and description to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

grazitti_sapna
Super User
Super User

Hi @gchn 

Try using:-

new_measure =
VAR CurrentDate = MAX('YourTable'[date])
VAR PrevDate =
CALCULATE(
MAX('YourTable'[date]),
FILTER(
ALL('YourTable'),
'YourTable'[date] < CurrentDate &&
'YourTable'[A1] = EARLIER('YourTable'[A1]) &&
'YourTable'[A2] = EARLIER('YourTable'[A2]) &&
...
)
)
RETURN
IF(ISBLANK(PrevDate), BLANK(),
CALCULATE(
MAX('YourTable'[value]),
FILTER(
ALL('YourTable'),
'YourTable'[date] = PrevDate &&
'YourTable'[A1] = EARLIER('YourTable'[A1]) &&
'YourTable'[A2] = EARLIER('YourTable'[A2]) &&
...
)
)
)
Hope this will help.

gchn
Frequent Visitor

Just the EARLIER function doesnt' work, can you be more specific?

Mkarwa-123
Resolver II
Resolver II

@gchn try to use earlier() DAX function
EARLIER(<column>, <number>)

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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