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
carocaro81
New Member

Fill calculated column and replace null value with previous values of same Year

Hello All,

I need your help with DAX functions please. I’m looking for a solution for the below case:

I have to fill the column [ForecastAmount] (for each combination [Article-ID] & [Customer-ID] & [Time-ID]).

 In case the [SalesAmount] for a row was 0 (for each combination [Article-ID] & [Customer-ID] & [Time-ID]), I have to take the [SalesAmount] (not equals to ZERO or not NULL) of the last previous [Time-ID] available (for the same combination [Article-ID] and [Customer-ID]).

Also, the last previous [Time-ID] should be in the same year.

[ForcastAmount] is a calculated column.

I’m trying to solve this problem in Tabular Model in Visual Studio.

Many Thanks for your answers and guidance.

Caro

ForecastAmount2.png

 

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

HI @carocaro81,

 

You can try to use below measure to get recently non-blank sales amount:

Forcat Sales =
VAR Previous_Non_Zero_ID =
    MAXX (
        FILTER (
            ALL ( Table ),
            Table[Article-ID] = MAX ( Table[Article-ID] )
                && Table[Customer-ID] = MAX ( Table[Customer-ID] )
                && Table[Time-ID] < MAX ( Table[Time-ID] )
                && Table[SalesAmount] <> 0
        ),
        Table[Time-ID]
    )
RETURN
    IF (
        MAX ( Table[SalesAmount] ) = 0,
        LOOKUPVALUE (
            Table[SalesAmount],
            Table[Article-ID], MAX ( Table[Article-ID] ),
            Table[Customer-ID], MAX ( Table[Customer-ID] ),
            Table[Time-ID], Previous_Non_Zero_ID
        ),
        MAX ( Table[SalesAmount] )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

HI @carocaro81,

 

You can try to use below measure to get recently non-blank sales amount:

Forcat Sales =
VAR Previous_Non_Zero_ID =
    MAXX (
        FILTER (
            ALL ( Table ),
            Table[Article-ID] = MAX ( Table[Article-ID] )
                && Table[Customer-ID] = MAX ( Table[Customer-ID] )
                && Table[Time-ID] < MAX ( Table[Time-ID] )
                && Table[SalesAmount] <> 0
        ),
        Table[Time-ID]
    )
RETURN
    IF (
        MAX ( Table[SalesAmount] ) = 0,
        LOOKUPVALUE (
            Table[SalesAmount],
            Table[Article-ID], MAX ( Table[Article-ID] ),
            Table[Customer-ID], MAX ( Table[Customer-ID] ),
            Table[Time-ID], Previous_Non_Zero_ID
        ),
        MAX ( Table[SalesAmount] )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.