Forum Discussion

Lew_14's avatar
Lew_14
Frequent Visitor
4 years ago

Populate missing data using last populated row

I'm looking for some help!

 

I have a table that shows minute-by-minute data logs for machines in a production environment. Each row should have a 'RefNo' value however i'm finding that the last set of data logs always has this value missing and unfortunately there's no way i can apply a fix at source.

 

I require a new column that basically contains the following logic:

If the current rows' 'RefNo' field is blank, bring across the last logged value in 'RefNo' until the 'Value' resets to 0. I've tried a few different solutions but my DAX isn't up to scratch to get everything working.

 

Below is a snapshot of my data and i would expect a solution to populate rows 110-124 with 'REF001', after which a new production run ('REF002') begins (however i'm also seeing the same issue with data logs not being captured at the very start of the run, which isn't currently an issue considering what i'm trying to achieve).

 

 

Any help/guidance would be massively appreciated!

 

 

 

 

 

8 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hello Lew_14 

    You can create a calculated column. If RefNo is blank and value > 0 then Index else blank().

    • Lew_14's avatar
      Lew_14
      Frequent Visitor

      I'm not sure how that would work, Tarun. Could you please explain further? I've previously added a calculated column that brings across the previous RefNo if the current RefNo is blank (using the Index, DAX below) but obviously that only works for the last populated row +1, whereas i need all unpopulated rows to be filled in with the RefNo for that particular run.

       

      RefNo (amended) = if(ISBLANK('TABLE'[RefNo]),LOOKUPVALUE('TABLE'[RefNo],'TABLE'[Index],'TABLE'[Index]-1),'TABLE'[RefNo])
       
      It could work by capturing the index of the last populated row of RefNo for any given run and then bring across that variable to any row where the RefNo is blank, however i'm not sure how i'd do this.
       
      Many thanks
      • Anonymous's avatar
        Anonymous
        Not applicable

        Hello Lew_14 
        Could you please share the pbix file after removing the sensitive information? Also, please share the expected outcome also.

        Thank You.