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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
awitt
Helper III
Helper III

First instance value - second instance 0

I have orders data that can feature several shipments per one order. Inisde those split shipments could be multiple items and the orders data has a different line for each item. I am looking to return the two columns highlighted below.

 

The first column is capturing the first instance of a unique OrderID / Tracking field and returning the cost associate while the other instances of that same value are assigned a "0". The second column is doing basically the same thing only counting the first intance and 0ing out the others. I will be eventually summing the column values or finding column averages for different analysis. 

 

Capture.PNG

 

 

1 ACCEPTED SOLUTION
TeigeGao
Solution Sage
Solution Sage

Hi @awitt ,

Please refer to the following DAX query:

Shipping Cost per order =
IF (
    'Table'[Item]
        = CALCULATE (
            MIN ( 'Table'[Item] ),
            TOPN (
                1,
                FILTER ( ALL ( 'Table' ), 'Table'[Tracking] = EARLIER ( 'Table'[Tracking] ) ),
                'Table'[Item], ASC
            )
        ),
    'Table'[Cost],
    0
)

Number of Ships Per order =
IF ( 'Table'[Shipping Cost per order] <> 0, 1, 0 )

The result will like below:

PBIDesktop_FwueYEAARS.png

Best Regards,

Teige

View solution in original post

1 REPLY 1
TeigeGao
Solution Sage
Solution Sage

Hi @awitt ,

Please refer to the following DAX query:

Shipping Cost per order =
IF (
    'Table'[Item]
        = CALCULATE (
            MIN ( 'Table'[Item] ),
            TOPN (
                1,
                FILTER ( ALL ( 'Table' ), 'Table'[Tracking] = EARLIER ( 'Table'[Tracking] ) ),
                'Table'[Item], ASC
            )
        ),
    'Table'[Cost],
    0
)

Number of Ships Per order =
IF ( 'Table'[Shipping Cost per order] <> 0, 1, 0 )

The result will like below:

PBIDesktop_FwueYEAARS.png

Best Regards,

Teige

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.