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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

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
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.

Top Kudoed Authors