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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
sguzman
Regular Visitor

How to get the lastnonblank value when I need to keep several columns in context

Test file 

Last nonblank column = 
CALCULATE(
SUM('query (18)'[Actuals]),
LASTNONBLANK('query (18)'[Reporting Month].[Month],1),ALL('query (18)'[Equipment],'query (18)'[Factory])
)

 

 

 

 

 

 

 

 

Hello,

I have summarised my problem using a few rows. I have some equipments (types) that are used in one or more factories. Every month, there should be a value for defective items (called Actuals in the table underneath.) Not all combinations of equipments and factories have values on every month, thus the need to use the lastnonblank function to get a new column.

 

I attempted to recreate some suggestions from tutorials of the PBI community, but I cannot manage to get the context right (level of detail.) I have used Tableau so far, and this is my first PBI attempt. In Tableau terms: fixed on every equipment and factory, return the last nonblank value based on all months that have been published. I do not have enable the function to add screenshots or the file, so here is the table. 

 

I tried to copy my table, but somehow when a cell is blank, the row loses its column and the format is corrupted. To avoid this problem, I have replaced all blank values with zeros. Please, replace back all  blanks to have the actual values and make the exercise relevant (otherwise nothing will be blank.)

FactoryReporting MonthEquipmentActualsMonth
Factory 12021-01Equipment 101/1/2021
Factory 12021-01Equipment 2 32.31/1/2021
Factory 12021-01Equipment 331/1/2021
Factory 12021-01Equipment 401/1/2021
Factory 12021-01Equipment 5131/1/2021
Factory 12021-01Equipment 601/1/2021
Factory 12021-01Equipment 701/1/2021
Factory 12021-02Equipment 102/1/2021
Factory 12021-02Equipment 202/1/2021
Factory 12021-02Equipment 402/1/2021
Factory 12021-02Equipment 5102/1/2021
Factory 12021-02Equipment 602/1/2021
Factory 12021-02Equipment 702/1/2021
Factory 12021-03Equipment 1433/1/2021
Factory 12021-03Equipment 2 25.63/1/2021
Factory 12021-03Equipment 403/1/2021
Factory 12021-03Equipment 503/1/2021
Factory 12021-03Equipment 6343/1/2021
Factory 12021-03Equipment 703/1/2021
Factory 12021-04Equipment 1574/1/2021
Factory 12021-04Equipment 2 38.54/1/2021
Factory 12021-04Equipment 4644/1/2021
Factory 12021-04Equipment 504/1/2021
Factory 12021-04Equipment 604/1/2021
Factory 12021-04Equipment 704/1/2021
Factory 22021-01Equipment 3431/1/2021
Factory 22021-02Equipment 3872/1/2021
Factory 22021-02Equipment 3232/1/2021
Factory 22021-03Equipment 303/1/2021
Factory 22021-03Equipment 303/1/2021
Factory 22021-04Equipment 304/1/2021
Factory 22021-04Equipment 304/1/2021
Factory 32021-01Equipment 3761/1/2021
Factory 32021-02Equipment 302/1/2021
Factory 32021-03Equipment 3683/1/2021
Factory 32021-04Equipment 304/1/2021
Factory 42021-01Equipment 3301/1/2021
Factory 42021-02Equipment 3872/1/2021
Factory 42021-03Equipment 303/1/2021
Factory 42021-04Equipment 304/1/2021
Factory 22021-01Equipment 701/1/2021
Factory 22021-02Equipment 702/1/2021
Factory 22021-03Equipment 703/1/2021
Factory 22021-04Equipment 704/1/2021

 

Thanks,

Sonia

1 ACCEPTED SOLUTION

@sguzman,

 

Here's a work-around in which you overlay one matrix with another. The visual below is actually two matrices:

 

DataInsights_0-1617112968343.png

The first (top) matrix:

 

DataInsights_1-1617113093892.png

The second (bottom) matrix:

 

DataInsights_2-1617113255298.png

 

Enable column auto-size for each matrix:

 

DataInsights_3-1617113377832.png

 

The first (top) matrix should be brought to front:

 

DataInsights_4-1617113487045.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

12 REPLIES 12
DataInsights
Super User
Super User

@sguzman,

 

Here are two ways to achieve this with measures. You can use either LASTNONBLANK or LASTNONBLANKVALUE.

 

Sum Actuals = SUM ( Equipment[Actuals] )

Last Nonblank =
CALCULATE (
    SUM ( Equipment[Actuals] ),
    LASTNONBLANK ( Equipment[Month], [Sum Actuals] )
)

Last Nonblank Value = 
LASTNONBLANKVALUE ( Equipment[Month], [Sum Actuals] )

 

DataInsights_0-1616957957100.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Could you please advise, how i can get correct total amount ? For all factory and equipment.

Hi DataInsights,

I am unable to replicate your suggestions. This is really my first formula. And due to my fault, I mix the names in the tables with the names in the code. Factory = Entities. You had, depite my mix up, manage to get the values that are needed. I just cannot execute in my file. I get an error regarding "a circular dependency was detected.

 

This is the first time I upload a file in OneDrive. Hope it works. Can you help  me implement the formula within ?

 

Thanks,

Sonia

@sguzman,

 

Regarding the question about extending row color banding, you can try adjusting these Formatting properties:

 

Style
Row headers —> Stepped layout
Values —> Banded row style





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@sguzman,

 

You created a calculated column instead of a measure; the measure does not have a circular dependency. Try this measure:

 

Last Nonblank Value =
LASTNONBLANKVALUE ( 'query (18)'[Month], [SUM Actuals] )

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi,

I am so close. Using a measure, as you suggested, I am able to get the right numbers and display them in a table. But I am now facing problems to display this data in the Matrix visual. I am unable to add measures in the row category of the Matrix. I tried to convert the measure to TEXT using FORMAT, but I got again the problem of a circular reference. Can you maybe me throw a few suggestions on how to overcome this ? I updated the PBI file in the One Drive link

 

Thanks,

Sonia

@sguzman,

 

Measures belong in the Values field well of a matrix, and dimensions belong in the Rows and Columns field wells. Do you have a mockup of the visual you are trying to create?

 

Also, I noticed that you're not using the measure [SUM Actuals] in the second argument of LASTNONBLANKVALUE. Either use [SUM Actuals] or CALCULATE ( SUM ( 'query (18)'[Actual] ) ). Using the measure [SUM Actuals] as the second argument is simpler, and it results in an implicit CALCULATE, which is necessary for the correct calculation.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi,

I have added the [Sum Actuals] in the calculation. I refreshed the file with a mock up of what I am expecting. I attempted to convert the measure Last Nonblank into text using FORMAT. I thought that as such, I would be able to add it to the matrix (I would that in Tableau.) But it did not work. I now get a row for every month where I have data. I am lost. I appreciate you taking your time to help me iterate. 

 

Sonia

@sguzman,

 

Here's a work-around in which you overlay one matrix with another. The visual below is actually two matrices:

 

DataInsights_0-1617112968343.png

The first (top) matrix:

 

DataInsights_1-1617113093892.png

The second (bottom) matrix:

 

DataInsights_2-1617113255298.png

 

Enable column auto-size for each matrix:

 

DataInsights_3-1617113377832.png

 

The first (top) matrix should be brought to front:

 

DataInsights_4-1617113487045.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks so much. You were very nice to work on the workaround for me. Really appreciate it.

 

Sonia

lbendlin
Super User
Super User

Thank you for providing sample data. However it does not match your measure definition. Some column headers are spelled differently, and the Entities column is missing from the sample.  In addition you are using a  date hierarchy on the Month field.  I would recommend you use a proper calendar table instead.

Hi, I apologize for the mix up. I had created a Power BI file with the data, table and formula. I ended up adding a manual table and put easier names to understand without the context of all the explanation I had in the file.  Unfortunately, I forgot to update the names in the code. Hopefuly, you can stull help me. I have updated the code. Factories and Entities are synonyms. And yes, I do have a calendar table.

 

Thansk,

Sonia

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.