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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
char23
Helper II
Helper II

How to lookup and compare data in the same table

Hello, I need help with adding a new column. Is there a way to lookup values/compare data in the same table? I have schedule data that will be added to the table for each month. Most values in the ID column will repeat each month, and there will be some IDs that are removed or added. I am trying to add a new column to the same table that shows the status of the previous month. Columns Status and Schedule Status are calculated columns with Dax. Any help to put me in the right directions is useful. 

 

 

 

ID

StatusSchedule StatusPrevious Status
ABCOn timePrevious 
DEFNot on TimePrevious 
GHIFuturePrevious 
JKLOn timePrevious 
ABCOn timeCurrentOn time
DEFOn timeCurrentNot on Time
GHIOn timeCurrentFuture
JKLOn timeCurrentOn time
MNOOn timeCurrentAdded
1 ACCEPTED SOLUTION
samratpbi
Super User
Super User

Hi, I created the below table:

samratpbi_0-1721337443424.png

Then created the below measure:

Prev Status =
VAR _selectedID = SELECTEDVALUE(PreviousStat[ID])
VAR _preVal =
CALCULATE
(
    MIN(PreviousStat[Schedule Status]),
    PreviousStat[ID] = _selectedID,
    ALLEXCEPT(PreviousStat, PreviousStat[Previous Status]),
    PreviousStat[Previous Status] <> "Current"        
)
RETURN
IF(
    SELECTEDVALUE(PreviousStat[Previous Status]) <> "Current",
    "",
    IF(
        ISBLANK(_preVal), "Added",
        _preVal
    )
)
And the output:
samratpbi_1-1721337759210.png

If this helps to resolve your problem, then please mark it as solution! Thanks

Dont forget to give Kudos 🙂

 

View solution in original post

2 REPLIES 2
samratpbi
Super User
Super User

Hi, I created the below table:

samratpbi_0-1721337443424.png

Then created the below measure:

Prev Status =
VAR _selectedID = SELECTEDVALUE(PreviousStat[ID])
VAR _preVal =
CALCULATE
(
    MIN(PreviousStat[Schedule Status]),
    PreviousStat[ID] = _selectedID,
    ALLEXCEPT(PreviousStat, PreviousStat[Previous Status]),
    PreviousStat[Previous Status] <> "Current"        
)
RETURN
IF(
    SELECTEDVALUE(PreviousStat[Previous Status]) <> "Current",
    "",
    IF(
        ISBLANK(_preVal), "Added",
        _preVal
    )
)
And the output:
samratpbi_1-1721337759210.png

If this helps to resolve your problem, then please mark it as solution! Thanks

Dont forget to give Kudos 🙂

 

Thank you for sending this. This seems to help a lot! However I am trying to alter this for my data and should have provided more details initially. My [Previous Status] column is actually a series of numbers where 1 = current, 2= previous, and >2 = old data that I want to ignore. I've tried altering your formula similar to what is below (red text below table), but I keep getting "Added" for every record in the new column. I want to add the column in green. Also, will eventually have to add to show deleted records (May need another column for this, i'm not sure) 

 

IDSchedule StatusPrevious StatusPrev Status (from Previous status =2) 
ABCNot Started3 
DEFNot Started3 
GHINot Started3 
JKLNot Started3 
ABCOn time 2 
DEFNot on Time2Deleted (Not found from Previous status =1)
GHIFuture2 
JKLOn time 2 
ABCOn time 1On time
GHIOn time 1Future
JKLOn time 1On time
MNOOn time 1Added

 

Prev Status =
VAR _selectedID = SELECTEDVALUE(PreviousStat[ID])
VAR _preVal =
CALCULATE
(
    MIN(PreviousStat[Schedule Status]),
    PreviousStat[ID] = _selectedID,
    ALLEXCEPT(PreviousStat, PreviousStat[Previous Status]),
    PreviousStat[Previous Status] = 2        
)
RETURN
IF(
    SELECTEDVALUE(PreviousStat[Previous Status]) > 1,
    "",
    IF(
        ISBLANK(_preVal), "Added",
        _preVal
    )
)

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

Find out what's new and trending in the Fabric community.