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
em_001
New Member

Sum spend of the most recent version in each category

Hi, would someone be able to help me create a custom column in power query editor? 
 
em_001_1-1701115945281.png
I have a table with 3 columns:
1: PO (Purchase order #)
2: Revision (each time the dollars spent changes, the PO is revised. The POs are revised 0-3 times)
3: Spend 
 
Each PO# can have multiple lines to account for:
1: Multiple line items
2: Revisions 
 
I would like to create a "Current Spend" column in power query that pulls over the spend for the most recent (highest # revision) per PO. This column should have blanks or 0 for any previous revisions of the PO. If 0 revisions were made, it should still pull over the spend for that revision. 
 
For example: 
 
em_001_2-1701116950832.png

 

 
Thank you!! 
 
 
1 ACCEPTED SOLUTION
v-weiyan1-msft
Community Support
Community Support

Hi @em_001 ,

 

Please try code as below to create a custom column .

 

if [Rsvision] = List.Max(
    let
    _PO = [PO]
    in
    Table.SelectRows(#"Changed Type",each _PO = [PO])[Rsvision]
    )
    then [Spend] else null

 

My Sample and result are as below.

vweiyan1msft_0-1701222988538.png

 

Best Regards,

Yulia Yan

 

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

2 REPLIES 2
AlienSx
Super User
Super User

Hello, @em_001 

    f = (tbl as table) as table =>
        [maxr = List.Max(tbl[Revision]),
        cs  = Table.AddColumn(tbl, "Current Spend", each if [Revision] = maxr then [Spend] else null)][cs],
    g = Table.Group(Source, "PO#", {{"rows", each f(_)}}),
    expand = Table.ExpandTableColumn(g, "rows", {"Revision", "Spend", "Current Spend"})
v-weiyan1-msft
Community Support
Community Support

Hi @em_001 ,

 

Please try code as below to create a custom column .

 

if [Rsvision] = List.Max(
    let
    _PO = [PO]
    in
    Table.SelectRows(#"Changed Type",each _PO = [PO])[Rsvision]
    )
    then [Spend] else null

 

My Sample and result are as below.

vweiyan1msft_0-1701222988538.png

 

Best Regards,

Yulia Yan

 

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

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors