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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
mgcchkn
Frequent Visitor

Get last non blank value in column to calculate missed production by date

This has me wanting to throw my laptop out the window and bang my head against a wall.

 

See image for details, but I'm trying to return the last non blank "production" amount to calculate "missed production" for days where there were down hours.  (so first example is ends up being E4/24*D5 and E4/24*D6, and then E10/24*D11)

 

Using Excel just for illustration purposes.

 

2024-03-11_11-02-47.png

 

Thank you,

Eric

1 ACCEPTED SOLUTION

Usually, TOPN() is more concise way to handle such scenarios.

ThxAlot_0-1710230631742.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



View solution in original post

7 REPLIES 7
ThxAlot
Super User
Super User

ThxAlot_0-1710182548235.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



Your solution works as described.  I messed up my example dataset though. 

My dataset does contain a number in the Production column (between 0-100) even when there is Down Hours.  So I'd need it to find the last day that didn't have Down Hours instead of the lastnonblank.  I thought I had it when I removed the <= and just made it a < but it got the previous number because it wasn't a blank. 

mgcchkn_0-1710188998769.png

 

 

Sorry for messing that up.

Hm... I really doubt it would work by just removing "=" from "<="; you can observe it on 2024/1/18 (or any Down in a row).



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



Hi @mgcchkn 

 

First of all, thanks @ThxAlot for your contribution to the forum.

 

Maybe you can try this:
Create a calculate column in the table:

Missed production = 
VAR _previousDate =
    IF (
        'Table'[Down Date] <> BLANK (),
        CALCULATE (
            MAX ( 'Table'[Date] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[Date] < EARLIER ( 'Table'[Date] )
                    && 'Table'[Down Date] = BLANK ()
            )
        )
    )
VAR _previousProduction =
    CALCULATE (
        SELECTEDVALUE ( 'Table'[Production] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Date] = _previousDate )
    )
RETURN
    ( _previousProduction / 24 ) * 'Table'[Down Hours]

The result is as follow:

vzhengdxumsft_0-1710224100238.png

If the above one can't help you, could you please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

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

Thank you for the response!  For some reason when I do this, I don't get any results.  I'll have to play with it some more to see where I'm going wrong.  @ThxAlot 's 2nd solution did work however.

Usually, TOPN() is more concise way to handle such scenarios.

ThxAlot_0-1710230631742.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



Thank you, @ThxAlot !  This worked perfectly!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.