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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
PaulBoden
Helper I
Helper I

Updating table rows based on earlier row

Hi all,

 

I have a solution that needs to integrate manual updates during downtimes before eventually reconciling the data once the correct information becomes available at source.

 

The solution needs to:

  • Find instances where a flag has indicated a manual adjustment has been made to a user entry
  • Identify any entries associated with this user ID between the date on which the manual adjustment was made and the date on which the source data has been updated to reflect the manual adjustment (if applicable)
  • Apply a specific set of adjustments to the identified rows, dependent on the nature of the adjustment.

 

Considering the attached table, I’ve tried to outline the logic I’m trying to implement below:

For the purposes of this explanation, I’ll refer to the manual adjustment as row X.

 

IF Flag = “Adj” (

                IF Case = “L” (

                                For any Date >=  Than X.Date WHERE ID = X.ID And Case != X.Case

                                                Output = “H”

                )

                IF Case = “M” (

                                For any Date >=  Than X.Date WHERE ID = X.ID And Case != X.Case

                                                Level = X.Level

                )

)

 

Any advice on how to optimally achieve this within PowerBI would be greatly appreciated.

 

IDCaseFlagLevelDateOutput

1HCSource103/07/2024S
1HCSource104/07/2024S
1LAdj105/07/2024S
1HCSource106/07/2024S
1HCSource107/07/2024S
1LSource108/07/2024S
1HCSource109/07/2024S
1HCSource110/07/2024S
1HCSource111/07/2024S
1HCSource112/07/2024S
2HCSource303/07/2024S
2HCSource304/07/2024S
2HCSource305/07/2024S
2HCSource306/07/2024S
2HCSource307/07/2024S
2LSource308/07/2024S
3HCSource303/07/2024S
3HCSource304/07/2024S
3HCSource305/07/2024S
3HCSource306/07/2024S
3HCSource307/07/2024S
3LAdj308/07/2024S
3HCSource309/07/2024S
3HCSource310/07/2024S
3HCSource311/07/2024S
3HCSource312/07/2024S
4HCSource503/07/2024S
4HCSource504/07/2024S
4LAdj505/07/2024S
4HCSource505/07/2024S
4HCSource506/07/2024S
4HCSource507/07/2024S
4HCSource508/07/2024S
4HCSource509/07/2024S
4HCSource510/07/2024S
4HCSource511/07/2024S
4LSource512/07/2024S
5HCSource203/07/2024S
5MAdj304/07/2024S
5HCSource204/07/2024S
5HCSource205/07/2024S
5HCSource206/07/2024S
5HCSource207/07/2024S
5HCSource208/07/2024S
5MSource309/07/2024S
5HCSource310/07/2024S
5HCSource311/07/2024S
5HCSource312/07/2024S
5HCSource313/07/2024S
1 ACCEPTED SOLUTION
Sahir_Maharaj
Super User
Super User

Hello @PaulBoden,

 

Can you please try the following:

 

1. Identify Adjustment Rows

IsAdjustment = 
IF (
    Data[Flag] = "Adj",
    TRUE(),
    FALSE()
)

2. Apply the logic for updating the Output column

AdjustedOutput = 
VAR CurrentID = Data[ID]
VAR CurrentDate = Data[Date]
VAR CurrentCase = Data[Case]
VAR AdjustmentDate = 
    CALCULATE (
        MIN(Data[Date]),
        FILTER (
            Data,
            Data[ID] = CurrentID && 
            Data[Flag] = "Adj" && 
            Data[Date] <= CurrentDate
        )
    )
VAR AdjustmentCase = 
    CALCULATE (
        FIRSTNONBLANK(Data[Case], 1),
        FILTER (
            Data,
            Data[ID] = CurrentID && 
            Data[Flag] = "Adj" && 
            Data[Date] = AdjustmentDate
        )
    )
VAR AdjustmentLevel = 
    CALCULATE (
        FIRSTNONBLANK(Data[Level], 1),
        FILTER (
            Data,
            Data[ID] = CurrentID && 
            Data[Flag] = "Adj" && 
            Data[Date] = AdjustmentDate
        )
    )
RETURN 
    IF (
        Data[Flag] <> "Adj" && Data[Date] >= AdjustmentDate,
        IF (
            AdjustmentCase = "L",
            "H",
            IF (
                AdjustmentCase = "M",
                AdjustmentLevel,
                Data[Output]
            )
        ),
        Data[Output]
    )

Let me know if you might require any further assistance.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

View solution in original post

2 REPLIES 2
dufoq3
Super User
Super User

Hi @PaulBoden, could you provide expected result based on sample data pls?


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Sahir_Maharaj
Super User
Super User

Hello @PaulBoden,

 

Can you please try the following:

 

1. Identify Adjustment Rows

IsAdjustment = 
IF (
    Data[Flag] = "Adj",
    TRUE(),
    FALSE()
)

2. Apply the logic for updating the Output column

AdjustedOutput = 
VAR CurrentID = Data[ID]
VAR CurrentDate = Data[Date]
VAR CurrentCase = Data[Case]
VAR AdjustmentDate = 
    CALCULATE (
        MIN(Data[Date]),
        FILTER (
            Data,
            Data[ID] = CurrentID && 
            Data[Flag] = "Adj" && 
            Data[Date] <= CurrentDate
        )
    )
VAR AdjustmentCase = 
    CALCULATE (
        FIRSTNONBLANK(Data[Case], 1),
        FILTER (
            Data,
            Data[ID] = CurrentID && 
            Data[Flag] = "Adj" && 
            Data[Date] = AdjustmentDate
        )
    )
VAR AdjustmentLevel = 
    CALCULATE (
        FIRSTNONBLANK(Data[Level], 1),
        FILTER (
            Data,
            Data[ID] = CurrentID && 
            Data[Flag] = "Adj" && 
            Data[Date] = AdjustmentDate
        )
    )
RETURN 
    IF (
        Data[Flag] <> "Adj" && Data[Date] >= AdjustmentDate,
        IF (
            AdjustmentCase = "L",
            "H",
            IF (
                AdjustmentCase = "M",
                AdjustmentLevel,
                Data[Output]
            )
        ),
        Data[Output]
    )

Let me know if you might require any further assistance.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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