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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
RyanBentham
Kudo Kingpin
Kudo Kingpin

DAX help lastnonblank

I have a table with some sample data:

 

Date DateIndex Project Value
01/01/2020 1 A 5
02/01/2020 2 A 10
03/01/2020 3 A 17
04/01/2020 4 A 25
05/01/2020 5 A 36
       
06/01/2020 1 B 7
07/01/2020 2 B 12
08/01/2020 3 B 13
09/01/2020 4 B 13
10/01/2020 5 B 20
       
16/02/2020 1 C 10
17/02/2020 2 C 18
18/02/2020 3 C 23

 

 

From this I'm creating a table visual as follows:

 

Project | Dates 12345
A 510172536
B 712131320
C 101823  

 

As you can see, project C will have no value for dates 4 & 5 with it not exisiting in the dataset 

 

What i'm trying to do is create a dax measure that will populate the gaps in the table above with the lastnonblank value for the particular project.     So the outcome would be like the below, with the value of 23 being assigned to dates 4 & 5.

 

Project | Dates 12345
A 510172536
B 712131320
C 1018232323

 

Realistically there would be 10 to 20 projects with various dates, but I would want every projects to go to the max available dateindex,  carrying forward any last non blank value

 

Any ideas?

1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi @RyanBentham 

You can try the following steps.

 

1 Create a Calculated table

New Table = CROSSJOIN(VALUES('Table'[Project]),VALUES('Table'[DateIndex]))

 

2 Create a Measure

Filled Value =

VAR max_index =

    CALCULATE (

        MAX ( 'New Table'[DateIndex] ),

        ALLEXCEPT ( 'New Table', 'New Table'[Project] ),

        NOT ( ISBLANK ( 'New Table'[Value] ) )

    )

VAR max_val =

    CALCULATE (

        MAX ( 'New Table'[Value] ),

        FILTER (

            ALL ( 'New Table' ),

            'New Table'[Project] = SELECTEDVALUE ( 'New Table'[Project] )

                && 'New Table'[DateIndex] = max_index

        )

    )

VAR res =

    IF (

        ISBLANK ( SELECTEDVALUE ( 'New Table'[Value] ) ),

        max_val,

        SELECTEDVALUE ( 'New Table'[Value] )

    )

RETURN

    IF (

        HASONEFILTER ( 'New Table'[Project] ) && HASONEFILTER ( 'New Table'[DateIndex] ),

        res,

        IF (

            HASONEFILTER ( 'New Table'[Project] ),

            CALCULATE (

                SUM ( 'New Table'[Value] ),

                ALLEXCEPT ( 'New Table', 'New Table'[Project] )

            ),

            CALCULATE (

                SUM ( 'New Table'[Value] ),

                ALLEXCEPT ( 'New Table', 'New Table'[DateIndex] )

            )

        )

    )

 

The result looks like this:

v-cazheng-msft_0-1616487380415.png

 

For more details, you can refer the attached pbix.

 

Best Regards

Caiyun Zheng

 

Is that the answer you're looking for? 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

4 REPLIES 4
v-cazheng-msft
Community Support
Community Support

Hi @RyanBentham 

You can try the following steps.

 

1 Create a Calculated table

New Table = CROSSJOIN(VALUES('Table'[Project]),VALUES('Table'[DateIndex]))

 

2 Create a Measure

Filled Value =

VAR max_index =

    CALCULATE (

        MAX ( 'New Table'[DateIndex] ),

        ALLEXCEPT ( 'New Table', 'New Table'[Project] ),

        NOT ( ISBLANK ( 'New Table'[Value] ) )

    )

VAR max_val =

    CALCULATE (

        MAX ( 'New Table'[Value] ),

        FILTER (

            ALL ( 'New Table' ),

            'New Table'[Project] = SELECTEDVALUE ( 'New Table'[Project] )

                && 'New Table'[DateIndex] = max_index

        )

    )

VAR res =

    IF (

        ISBLANK ( SELECTEDVALUE ( 'New Table'[Value] ) ),

        max_val,

        SELECTEDVALUE ( 'New Table'[Value] )

    )

RETURN

    IF (

        HASONEFILTER ( 'New Table'[Project] ) && HASONEFILTER ( 'New Table'[DateIndex] ),

        res,

        IF (

            HASONEFILTER ( 'New Table'[Project] ),

            CALCULATE (

                SUM ( 'New Table'[Value] ),

                ALLEXCEPT ( 'New Table', 'New Table'[Project] )

            ),

            CALCULATE (

                SUM ( 'New Table'[Value] ),

                ALLEXCEPT ( 'New Table', 'New Table'[DateIndex] )

            )

        )

    )

 

The result looks like this:

v-cazheng-msft_0-1616487380415.png

 

For more details, you can refer the attached pbix.

 

Best Regards

Caiyun Zheng

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

@v-cazheng-msft   Thanks so much for you time in doing that.    Works a treat!!

amitchandak
Super User
Super User

@RyanBentham , Try a new measure like

 

if(isblank(max(Table[Value])), calculate(lastnonblankvalue(Table[DateIndex], max(Table[Value])), allexcept(Table, Table[project])), max(Table[Value]))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Thanks, although didn't quite work for me 😞

 

RyanBentham_0-1616074715472.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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