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
MarceloSaez
Helper I
Helper I

Fill blanks based in two conditions

Hello Everybody. I'm new to Power BI and I'm trying to fill blanks, but I haven't found a solution in this forum that exactly matches my specific problem. I hope the following clarifies the problem:

 

My Data:

Before.JPG

What I want to achieve:

After.JPG

 

I've tried the following (found here) but it doesn't work when it changes from "Producer" to "Injector":

StatusFilled = 
IF (
    Table[Status] = BLANK (),
    CALCULATE (
        LASTNONBLANK ( Table[Status], Table[Status] ),
        FILTER ( ALLEXCEPT ( Table, Table[Well] )Table[Date] <= EARLIER ( Table[Date] ) )
    ),
    Table[Status]
)

Any Ideas? Thanks in advance!!!

Regards,

 

Marce

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @MarceloSaez ,

 

How about this?

 

Column =
VAR FirstnotblankIndex =
    CALCULATE (
        MIN ( 'Table'[Index] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Status] <> BLANK ()
                && 'Table'[Well] = EARLIER ( 'Table'[Well] )
                && 'Table'[Index] <= EARLIER ( 'Table'[Index] )
        )
    )
VAR FirstnotblankStatus =
    CALCULATE (
        MIN ( 'Table'[Status] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Status] <> BLANK ()
                && 'Table'[Well] = EARLIER ( 'Table'[Well] )
                && 'Table'[Index] <= EARLIER ( 'Table'[Index] )
        )
    )
RETURN
    IF ( 'Table'[Index] >= FirstnotblankIndex, FirstnotblankStatus )

 

column.PNG

 

BTW, .pbix file attached.

 

 

Best Regards,

Icey

 

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

6 REPLIES 6
Icey
Community Support
Community Support

Hi @MarceloSaez ,

 

How about this?

 

Column =
VAR FirstnotblankIndex =
    CALCULATE (
        MIN ( 'Table'[Index] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Status] <> BLANK ()
                && 'Table'[Well] = EARLIER ( 'Table'[Well] )
                && 'Table'[Index] <= EARLIER ( 'Table'[Index] )
        )
    )
VAR FirstnotblankStatus =
    CALCULATE (
        MIN ( 'Table'[Status] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Status] <> BLANK ()
                && 'Table'[Well] = EARLIER ( 'Table'[Well] )
                && 'Table'[Index] <= EARLIER ( 'Table'[Index] )
        )
    )
RETURN
    IF ( 'Table'[Index] >= FirstnotblankIndex, FirstnotblankStatus )

 

column.PNG

 

BTW, .pbix file attached.

 

 

Best Regards,

Icey

 

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

Thanks a lot! It worked!

Best regards!

amitchandak
Super User
Super User

@MarceloSaez , Try a new column like

StatusFilled = 
IF (
    Table[Status] = BLANK (),
    CALCULATE (
        LASTNONBLANK ( Table[Status], Table[Status] ),
        FILTER ( Table, Table[Well] = EARLIER ( Table[Well] )  && Table[Date] <= EARLIER ( Table[Date] ) )
    ),
    Table[Status]
)

@amitchandak Thank you for your reply! I tried your modification but it continues doing the same thing... it almost does what I want except when there is a second change in the column "Status" for the same "Well", as shown in the picture. I want that when the Status changes to "InjectorWF" to continue down, but instead it comes back to "Productor Primaria".

Result.JPG

Thank you again, I'm learning a lot from the forum.

Regards!

 

Marce

I think I know what the problem is. The table comes initially from Power Query Editor, and is ordered using the index column.

1.JPG

but when apply changes, then the table becomes un-ordered, like in the following image:

2.jpg

I've tried using different sorting orders in Power Query Editor, but I always get the same result --> So LASTNONBLANK is working fine, but the problem is the order.

Any ideas why is this happening?

Hello again. I've been searching on this issue of Power BI not maintaining sort order when loading the query into the model. It seems like a memory optimization, which in large tables puts all the similar entries one after the other. This appears to be my case.

 

I haven't read any solutions to this change in the sort order, so apparently I can't overcome my problem using DAX ☹️. Is there a way of generating the StatusFilled column directly in the Power Editor, so that I have no need to do it in DAX?

 

Regards!

 

Marce

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.