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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
joshua1990
Post Prodigy
Post Prodigy

Calculate last entry per Order

Hi all,

ich have a sales table that shows multiple rows for each order since there are changes. Each change is recorded with a new version number:

Order Nr Value Version
1 5 1
1 4 2
2 9 1
3 7 1

 

Now I would like to calculate the sum [Value] for each order with latest version.

How would you do that? Using MAXX und Sum?

2 REPLIES 2
tamerj1
Super User
Super User

Hi @joshua1990 

please try

Sum of Last Version =
SUMX (
    VALUES ( 'Table'[Order Nr] ),
    CALCULATE ( MAXX ( TOPN ( 1, 'Table', 'Table'[Version] ), 'Table'[Value] ) )
)
daXtreme
Solution Sage
Solution Sage

 

 

[Total Value] =
// Be careful not to filter the Sales table
// by Value or Version because the measure
// here is sensitive to filters (which is
// OK and that's how it should be). For instance,
// if you filter by Order Nr and Version, then
// the version filtered by will be effective,
// not necessarily the latest one. If you don't
// filter by Version, you'll get what you want - 
// the latest version. Same for Value.
var OrdersWithLatestVersions = 
    generate(
        values( Sales[Order Nr] ),
        row( 
            "@LatestVersion", 
            calculate( max( Sales[Version] ) )
        )
    )
var Output =
    calculate(
        sum( Sales[Value] ),
        treatas(
            OrdersWithLatestVersions,
            Sales[Order Nr],
            Sales[Version]
        )
    )
return
    Output

 

Here's a different method:

 

[Total Value] =
sumx(
    generate(
        selectcolumns(
            values( Sales[Order Nr] ),
            "@OrderNumber", Sales[Order Nr]
        ),
        calculatetable(
            topn(1,
                Sales,
                Sales[Version],
                DESC
            )
        )
    ),
    Sales[Value]
)

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.