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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
KristinaSp
Helper I
Helper I

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

 

KristinaSp_0-1681306273153.png

KristinaSp_1-1681306656758.png

 

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

Hi @KristinaSp ,

 

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

(1) This is my test data.  

vtangjiemsft_0-1682406621786.png

(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.

vtangjiemsft_1-1682406644314.png

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. 

View solution in original post

1 REPLY 1
v-tangjie-msft
Community Support
Community Support

Hi @KristinaSp ,

 

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

(1) This is my test data.  

vtangjiemsft_0-1682406621786.png

(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.

vtangjiemsft_1-1682406644314.png

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. 

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.