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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
saidareddy_madi
Regular Visitor

Getting the previous record values

StoreNameFormDateSum of TotalScore
A09-11-2022 00:002
A05-05-2023 00:0095
A16-11-2023 00:0099
A23-04-2024 00:0098
A19-11-2024 00:0096
B02-11-2022 00:002
B12-04-2023 00:0094
B08-11-2023 00:0095
B09-04-2024 00:0090
B13-11-2024 00:0094
C15-11-2022 00:001
C12-04-2023 00:0092
C15-11-2023 00:0099
C17-04-2024 00:0089
C21-11-2024 00:0092
D15-11-2022 00:001
D12-04-2023 00:0094
D15-11-2023 00:0098
D17-04-2024 00:0096
D21-11-2024 00:0098

 

I have the in the above format and need to display the data in the table visual like the below format.

Store Name      Latest Score  Previous Score

A                            96                             98

B                            94                             90

C                            92                             89

D                            98                            96

 

Any ideas how to achive this in Power BI. Any inputs must be approciated. Thanks for advance.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @saidareddy_madi ,

I create a table as you mentioned.

vyilongmsft_0-1740547202768.png

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

vyilongmsft_1-1740547587954.png

 

 

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.                                     

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @saidareddy_madi ,

I create a table as you mentioned.

vyilongmsft_0-1740547202768.png

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

vyilongmsft_1-1740547587954.png

 

 

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.                                     

I have joined the new table with existing table, now it's filteing the previous values aswel.  it's worked fine.. thanks for your help. 

 

Thanks for your help, my requiremet got littlebit complicated.. these values will change based the year filter selected by the ender user in the slicer. 

ryedoesbi
New Member

You could use the RANKX function (descending order) where 1 = your latest date and 2 = your next latest date.  You could use the TOPN function to retrieve the top two values each category (i.e. latest date and second latest date) and use the MINX function to get the lowest of these two values.  You could use the INDEX function to retrieve the 2nd value from your list when ordered by descending date values.

 

There's lots of options with DAX 🙂

ChielFaber
Solution Specialist
Solution Specialist

The easiest way would probably to use the previous function. Check out visual calculations and the previous function

Using visual calculations in Power BI Desktop - Power BI | Microsoft Learn

A superb overview by Jeroen ter Heerdt:
Visual Calculations In Power BI
Hope this helps.


[Tip] Keep CALM and DAX on.
[Solved?] Hit “Accept as Solution” and leave a Kudos.
[About] Chiel | SuperUser (2023–2) |

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.