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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

DAX formula to find first greater than 0 value in a column

Hi,

 

i want to find out a DAX formula to get below calculated column (that is the result column that i want)

 

Excel.JPGlogic is as below

there are rows with different Code numbers and one code is considerd as one block (that means calculations should apply for each code separetly)

 

1. find out the first greater than 0 Stock value for each code

2. copy that value and 0 values (which are in above rows) to calculated column

3. all other values below to that value(1) should equal to value in Quantity column 

 

i have showed the expected output in 'calculated' column. 

 

Highly appricate any input

 

thank you

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create two columns

min_rank = RANKX(FILTER(Sheet2,Sheet2[code]=EARLIER(Sheet2[code])),[stock],,ASC,Dense)

Column =
VAR value_rank1 =
    CALCULATE (
        SUM ( [stock] ),
        FILTER ( ALLEXCEPT ( Sheet2, Sheet2[code] ), Sheet2[min_rank] = 1 )
    )
RETURN
    IF (
        value_rank1 = 0,
        IF ( [min_rank] = 1 || [min_rank] = 2, [stock], [quantity] ),
        IF ( [min_rank] = 1, [stock], [quantity] )
    )

1.png

Best Regards
Maggie

 

Community Support Team _ Maggie Li
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
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create two columns

min_rank = RANKX(FILTER(Sheet2,Sheet2[code]=EARLIER(Sheet2[code])),[stock],,ASC,Dense)

Column =
VAR value_rank1 =
    CALCULATE (
        SUM ( [stock] ),
        FILTER ( ALLEXCEPT ( Sheet2, Sheet2[code] ), Sheet2[min_rank] = 1 )
    )
RETURN
    IF (
        value_rank1 = 0,
        IF ( [min_rank] = 1 || [min_rank] = 2, [stock], [quantity] ),
        IF ( [min_rank] = 1, [stock], [quantity] )
    )

1.png

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

@v-juanli-msft  thank you very much. it works perfectly 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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 Solution Authors