Forum Discussion

PaulBoden's avatar
PaulBoden
Helper I
2 years ago
Solved

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
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi PaulBoden ,

    You can create a calculated column as below to get it, please find the details in the attachment.

    Output = 
    VAR _id = 'Table'[ID]
    VAR _date = 'Table'[Date]
    VAR _case = 'Table'[Case]
    VAR _level = 'Table'[Level]
    VAR _ladjdate =
        CALCULATE (
            MIN ( 'Table'[Date] ),
            FILTER (
                'Table',
                'Table'[ID] = _id
                    && 'Table'[Flag] = "Adj"
                    && 'Table'[Case] = "L"
            )
        )
    VAR _madjdate =
        CALCULATE (
            MIN ( 'Table'[Date] ),
            FILTER (
                'Table',
                'Table'[ID] = _id
                    && 'Table'[Flag] = "Adj"
                    && 'Table'[Case] = "M"
            )
        )
    RETURN
        IF (
            (
                'Table'[ID] = _id
                    && NOT ( ISBLANK ( _ladjdate ) )
                        && 'Table'[Date] >= _ladjdate
                        && 'Table'[Case] <> "L"
            )
                || (
                    'Table'[ID] = _id
                        && NOT ( ISBLANK ( _madjdate ) )
                            && 'Table'[Date] >= _madjdate
                            && 'Table'[Case] <> "M"
                            && 'Table'[Level] = _level
                ),
            "H"
        )

    Best Regards

5 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi PaulBoden ,

    I'm not clear about your requirement. Do you want to get the field [Output]? Could you please explain the judgement logic base on your provided sample data?

    Explain the judgement logic for it base on the sample data

    Expected result is Output field?

    Best Regards

    • PaulBoden's avatar
      PaulBoden
      Helper I

      Apologies for being unclear - The table should be formatted as below.

       

      IDCase  Flag Level Date Output
      1HCSource103/07/2024S
      1HCSource104/07/2024S
      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi PaulBoden ,

        Could you please explain the judgement logic of getting the field [Output] base on the shared sample data and below formula? For example: if xx="Adj" && xxx = xxx then xx 

        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
        
                        )
        
        )
        
         

        Best Regards