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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors