Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Getting the previous record values

StoreName FormDate Sum of TotalScore A 09-11-2022 00:00 2 A 05-05-2023 00:00 95 A 16-11-2023 00:00 99 A 23-04-2024 00:00 98 A 19-11-2024 00:00 96 B 02-11-2022 00:00 ...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi Anonymous ,

    I create a table as you mentioned.

    Then I think you can create a new table and here is the DAX code.

    NewTable = 
    SUMMARIZE (
        'Table',
        'Table'[StoreName],
        "Latest Score",
            CALCULATE (
                MAX ( 'Table'[Sum of TotalScore] ),
                'Table'[FormDate] = MAX ( 'Table'[FormDate] )
            ),
        "Previous Score",
            CALCULATE (
                MAX ( 'Table'[Sum of TotalScore] ),
                'Table'[FormDate]
                    = MAXX (
                        FILTER (
                            'Table',
                            'Table'[StoreName] = EARLIER ( 'Table'[StoreName] )
                                && 'Table'[FormDate] < MAX ( 'Table'[FormDate] )
                        ),
                        'Table'[FormDate]
                    )
            )
    )

     

     

    Best Regards

    Yilong Zhou

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.