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
Sica
Frequent Visitor

How to get the related date for the last non blank value of a another column

Hello!

I have not yet figured out a good way (in both Power Bi Desktop and/or Power Query) to get the date for the last non blank value of another column. In the example below, I would like to get the "Month" for each "Group" for the last know blank value of columns "Forecast 1", "Forecast 2" and "Forecast 3".

Sica_2-1638173940216.png

By using the colors, I am identifying the values I would like to have for each group and forecast columns. In the end, I would like to be able to get the date values as shown below:

Sica_3-1638173960494.png

Thank you for any tip you can provide.

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @Sica 

 

It's easier to solve your problem with calculated columns.

F1 date = 
CALCULATE (
    MAX ( 'Table'[Month] ),
    FILTER (
        'Table',
        [Group] = EARLIER ( 'Table'[Group] )
            && NOT ( ISBLANK ( 'Table'[Forecast1] ) )
    )
)
F1 value =
IF ( [Month] = [F1 date], [Forecast1], BLANK () )

vzhangti_0-1638413404303.png

 

"Forecast 2" and "forecast 3" also add calculated columns according to the above method.

F2 date =
CALCULATE (
    MAX ( 'Table'[Month] ),
    FILTER (
        'Table',
        [Group] = EARLIER ( 'Table'[Group] )
            && NOT ( ISBLANK ( 'Table'[Forecast2] ) )
    )
)
F2 value =
IF ( [Month] = [F2 date], [Forecast2], BLANK () )
F3 date =
CALCULATE (
    MAX ( 'Table'[Month] ),
    FILTER (
        'Table',
        [Group] = EARLIER ( 'Table'[Group] )
            && NOT ( ISBLANK ( 'Table'[Forecast3] ) )
    )
)
F3 value =
IF ( [Month] = [F3 date], [Forecast3], BLANK () )

vzhangti_1-1638413737966.png

 

The final result is shown in the figure, just as you expected.

vzhangti_3-1638413846079.png

 

 

Best Regards,

Community Support Team _Charlotte

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

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

Share data in a format that can be pasted in an MS Excel file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-zhangti
Community Support
Community Support

Hi, @Sica 

 

It's easier to solve your problem with calculated columns.

F1 date = 
CALCULATE (
    MAX ( 'Table'[Month] ),
    FILTER (
        'Table',
        [Group] = EARLIER ( 'Table'[Group] )
            && NOT ( ISBLANK ( 'Table'[Forecast1] ) )
    )
)
F1 value =
IF ( [Month] = [F1 date], [Forecast1], BLANK () )

vzhangti_0-1638413404303.png

 

"Forecast 2" and "forecast 3" also add calculated columns according to the above method.

F2 date =
CALCULATE (
    MAX ( 'Table'[Month] ),
    FILTER (
        'Table',
        [Group] = EARLIER ( 'Table'[Group] )
            && NOT ( ISBLANK ( 'Table'[Forecast2] ) )
    )
)
F2 value =
IF ( [Month] = [F2 date], [Forecast2], BLANK () )
F3 date =
CALCULATE (
    MAX ( 'Table'[Month] ),
    FILTER (
        'Table',
        [Group] = EARLIER ( 'Table'[Group] )
            && NOT ( ISBLANK ( 'Table'[Forecast3] ) )
    )
)
F3 value =
IF ( [Month] = [F3 date], [Forecast3], BLANK () )

vzhangti_1-1638413737966.png

 

The final result is shown in the figure, just as you expected.

vzhangti_3-1638413846079.png

 

 

Best Regards,

Community Support Team _Charlotte

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

Thank you so much!! 😀

EARLIER did the trick! This I was missing (it is a new function for me).

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.