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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
powerbiexpert22
Impactful Individual
Impactful Individual

expected value

i am using  two columns yearmonth and value in table visual as shown below, i need third column "expected_output" in same  table as highlighted below , this third column should pick up the first non zero value (example 0.05, 0.02 etc)  of current row and populate that same value and all previous rows including the current row 

 

powerbiexpert22_0-1746100961523.png

 

1 ACCEPTED SOLUTION

Hi @powerbiexpert22 

 

This dax code should work 

 

expected_output = 
VAR temp =
    TOPN (
        1,
        FILTER (
            Sheet1,
            Sheet1[yearmonth] >= EARLIER ( Sheet1[yearmonth] ) &&
            Sheet1[value] <> 0
        ),
        Sheet1[yearmonth], ASC
    )
VAR result =
    MINX ( temp, Sheet1[value] )
RETURN
    result

kushanNa_0-1746127376130.png

 

 

 

View solution in original post

5 REPLIES 5
kushanNa
Super User
Super User

Hi @powerbiexpert22 

 

Can you do this on power query side ? then it should be much easier than dax 

 

use this M code steps 

 

let
    Source = Csv.Document(File.Contents("C:\XXXX\data.csv"),[Delimiter=",", Columns=2, Encoding=65001, QuoteStyle=QuoteStyle.None]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"yearmonth", Int64.Type}, {"value", type number}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"yearmonth", Order.Descending}}),
    AddedIndex= Table.AddIndexColumn(#"Sorted Rows", "Index", 1, 1, Int64.Type),
 // Create a temporary column with 0/null replaced with null, others kept
    AddedTemp = Table.AddColumn(AddedIndex, "TempValue", each if [value] <> null and [value] <> 0 then [value] else null),

    // Fill down the cleaned column
    FilledDown = Table.FillDown(AddedTemp, {"TempValue"}),

    // Rename filled column
    Renamed = Table.RenameColumns(FilledDown, {{"TempValue", "FilledValue"}}),
    #"Sorted Rows1" = Table.Sort(Renamed,{{"yearmonth", Order.Ascending}})
in
    #"Sorted Rows1"

 

kushanNa_0-1746113785346.png

 

Hi @kushanNa ,

it should be in DAX

Hi @powerbiexpert22 

 

This dax code should work 

 

expected_output = 
VAR temp =
    TOPN (
        1,
        FILTER (
            Sheet1,
            Sheet1[yearmonth] >= EARLIER ( Sheet1[yearmonth] ) &&
            Sheet1[value] <> 0
        ),
        Sheet1[yearmonth], ASC
    )
VAR result =
    MINX ( temp, Sheet1[value] )
RETURN
    result

kushanNa_0-1746127376130.png

 

 

 

anilelmastasi
Super User
Super User

Hello @powerbiexpert22 ,

 

You can use this formula in your new calculated column:

 

Expected_Output =
VAR CurrentYM = [YearMonth]
VAR NonZeroTable =
FILTER (
ALL ( 'YourTable' ),
'YourTable'[YearMonth] <= CurrentYM && 'YourTable'[Value] <> 0
)
VAR FirstNonZero =
CALCULATE (
MIN ( 'YourTable'[YearMonth] ),
NonZeroTable
)
RETURN
CALCULATE (
MAX ( 'YourTable'[Value] ),
FILTER ( ALL ( 'YourTable' ), 'YourTable'[YearMonth] = FirstNonZero )
)

 

If this solved your issue, please mark it as the accepted solution.

Hi @anilelmastasi ,

it is returning same value 0.05 in all rows , please see below file

https://drive.google.com/file/d/1BUukgLhD1-p6B5rRE5Gro3sPhq91wW86/view?usp=drive_link

 

 

powerbiexpert22_0-1746104534482.png

 

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.