cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper I
Helper I

If value is missing insert last non missing value

Hi Power BI Community

 

I am struggling with something that should be really easy. When there is missing value for specific period I want to insert value from previos non-blank period. I tried using LASTNONBLANK but something isn't working. Here is the case visualized on example:

 

1. I have data structure like this:

1PBIC.JPG

 

2. When I pivot it it looks like this:

2PBIC.PNG

 

3. My desired result would be like this:

3PBIC.PNG

 

This is of course very simplified example on simple Excel data, but it reflects very correctly what I have in mind. One thing I should add is that in Power BI for creating Matrix table I use DimDate as a column.

 

Do you have any suggestions on how the measure/calculated column DAX code should look in this case?

 

Thank in advance for every tips!!

 

Regards,
Karol

2 REPLIES 2
Highlighted
Community Support
Community Support

Re: If value is missing insert last non missing value

Hi @KarolWojas ,

 

You can create calculated table first, then create column and measure using DAX below. Finally , put measure NonBlankValue onto Values box of Matrix visual.

 

Calculated Table:
Table = CROSSJOIN(DISTINCT(Table1[Item ]),CALENDAR(MIN(Table1[Date]),MAX(Table1[Date])))
 
Column:
Value = CALCULATE(FIRSTNONBLANK(Table1[Value],1),FILTER(ALLSELECTED(Table1),Table1[Item ]='Table'[Item ]&&Table1[Date]='Table'[Date]))
 
Meeasure:
NonBlankValue = var _lastdate=CALCULATE(MAX('Table'[Date]),FILTER(ALLEXCEPT('Table','Table'[Item ]),'Table'[Date]<MAX('Table'[Date])&&[Value]<>BLANK()))
return
IF(MAX('Table'[Value])=BLANK(),CALCULATE(MAX('Table'[Value]),FILTER(ALLEXCEPT('Table','Table'[Item ]),'Table'[Date]=_lastdate)),MAX('Table'[Value]))

Result:

 

62.png

 

Best Regards,

Amy

 

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

Highlighted
Helper I
Helper I

Re: If value is missing insert last non missing value

Hi Amy,

 

Thanks for the tip! It works fine with matrix table, but unforunately it doesn't work that great for charts (see screenshots below - they are coming from acutal data, not dummy one). In the charts I see that values are Also, the other thing is that my dataset is quite huge and I see that it takes a lot of time to process calculated table. Do you know if there is any way to do this inside the table I already have, without having to create calculated table?

 

This is how I see the result in chart. It shows maximum value in column, not sum of values in column:

1.PNG

 

2.PNG

 

Is there any easy way to deal with this?

 

Thanks in advance!

 

Karol

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

Super Users of the Quarter - Q2 2020

Super Users of the Quarter - Q2 2020

Who are our Super User Superstars? Who made it to the top of the leaderboards? Get the answers!

Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Community Summit Australia – Join Online!

Community Summit Australia – Join Online!

Be a part of the leading Microsoft Business Applications digital event, curated for the APAC community.

Top Solution Authors