Forum Discussion

KristinaSp's avatar
KristinaSp
Helper I
3 years ago
Solved

Fill blank values with previous max values

Hello,

 

I have found few similar topics, but neither helped with my issue.

 

I need to write measure, which fills empty values with previous max values.

And I almost did it.  In the table below, you can see, that I managed to fill 2022-09-24 and 2022-09-24 with previous max value (on 2022-09-23), becouse 2022-09-23 have only one value (only one row per day). If there are few rows (like in 2023-09-15), my measure does not work.

Any sollutions?

 

_max_value_no_blanks =

 

VAR latest_non_blank_date =

CALCULATE( MAX('Calendar'[Date]),

 FILTER(ALL('table),

 'table'[date] <=  MAX('Calendar'[Date]) &&

 'table'[value] <> 0

 ))

 

 VAR latest_non_blank_value =

 calculate( MAX('table'[value]),

 FILTER(ALL('Calendar'[Date]), 'Calendar'[Date] = latest_non_blank_date))

 

 RETURN

 

 latest_non_blank_rida

 

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi KristinaSp ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) This is my test data.  

    (2) We can create a measure. 

     

    fill blank = 
    var _a =CALCULATE(MAX('Table'[date]),FILTER(ALL('Table'),'Table'[date]<=MAX('Table'[date]) && 'Table'[value]<>BLANK()))
     var _b= CALCULATE(MAX('Table'[value]),FILTER(ALL('Table'),'Table'[date]<=_a))
     return 
     IF(MAX('Table'[value])=BLANK() && _a<>BLANK(),_b,MAX('Table'[value]))

     

    (3) Then the result is as follows.

    If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

     

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi KristinaSp ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) This is my test data.  

    (2) We can create a measure. 

     

    fill blank = 
    var _a =CALCULATE(MAX('Table'[date]),FILTER(ALL('Table'),'Table'[date]<=MAX('Table'[date]) && 'Table'[value]<>BLANK()))
     var _b= CALCULATE(MAX('Table'[value]),FILTER(ALL('Table'),'Table'[date]<=_a))
     return 
     IF(MAX('Table'[value])=BLANK() && _a<>BLANK(),_b,MAX('Table'[value]))

     

    (3) Then the result is as follows.

    If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

     

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly.