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
snaraya
Helper II
Helper II

Need to find null value for a column on basis of previous value and factor

Hello everyone ,

 

i have been working on below data for 3days and couldnt find a correct solution 

 

My sample data is as below

 

BUYearProjectionFactorIndexOutput
A201953.27 053.27
A202051.13 151.13
A202157.83 257.83
A202259.4 359.4
A2023 -0.027457.7962
A2024 0.036561.5384
A2025 0.036661.5384
A2026 0.036761.5384
A2027 0.036861.5384
A2028 0.036961.5384
A2029 0.0361061.5384
A2030 0.0361161.5384
B2019172.63 12172.63
B2020168.54 13168.54
B2021165.2 14165.2
B2022151.13 15151.13
B2023 0.06231316183.3871
B2024 0.06347717183.588
B2025 0.04538918180.4655
B2026 0.0319177.8089
B2027 0.0320177.8089
B2028 0.0321177.8089
B2029 0.0322177.8089
B2030 0.0323177.8089

 

to find the out column Output i used below DAX
Output =
VAR CurrentRow = 'Table'[Projection]
VAR PrevRow = CALCULATE( LASTNONBLANK('Table'[Projection],0 ), FILTER( 'Table', 'Table'[Index] < EARLIER('Table'[Index]) && NOT(ISBLANK('Table'[Projection])) ) )
VAR Factor = 'Table'[Factor] RETURN IF( ISBLANK(CurrentRow), PrevRow * (1 + Factor), CurrentRow )


the logic which i need is 

 

for 2023- Projection of 2022*(1+Factor)

for 2024- Projection of 2023(calculated in previous step) *(1+Factor) 

for 2025- Projection of 2024(calculated in previous step) *(1+Factor) and so on until 2030 for each BU

 

but my formula is using last non blank value of 2022 for calculating everything,so my 2023 value for both BU is correct from 2024 the value is wrong as it should use 2023 value to caculate 2024 and 2024 value for 2025 and so on

 

from 2019-2022 the data should be same

any help is appreciated  

2 ACCEPTED SOLUTIONS
wdx223_Daniel
Super User
Super User

Output = 
VAR _tbl =
    TOPN (
        1,
        FILTER (
            'Table',
            'Table'[BU] = EARLIER ( 'Table'[BU] )
                && NOT ( ISBLANK ( 'Table'[Projection] ) )
        ),
        'Table'[Year]
    )
VAR _FirstYear =
    MAXX ( _tbl, 'Table'[Year] )
VAR _BaseProjection =
    MAXX ( _tbl, 'Table'[Projection] )
RETURN
    IF (
        ISBLANK ( 'Table'[Projection] ),
        _BaseProjection
            * PRODUCTX (
                FILTER (
                    'Table',
                    'Table'[BU] = EARLIER ( 'Table'[BU] )
                        && 'Table'[Year] > _FirstYear
                        && 'Table'[Year] <= EARLIER ( 'Table'[Year] )
                ),
                1 + 'Table'[Factor]
            ),
        'Table'[Projection]
    )

wdx223_Daniel_0-1677557740952.png

 

View solution in original post

is the result correct?

wdx223_Daniel_0-1679903220347.png

Output =
VAR _tbl =
    TOPN (
        1,
        FILTER (
            'Table',
            'Table'[BU] = EARLIER ( 'Table'[BU] )
                && NOT ( ISBLANK ( 'Table'[Projection] ) )
                    && 'Table'[Year] < EARLIER ( 'Table'[Year] )
        ),
        'Table'[Year]
    )
VAR _FirstYear =
    MAXX ( _tbl, 'Table'[Year] )
VAR _BaseProjection =
    MAXX ( _tbl, 'Table'[Projection] )
VAR _tbl2 =
    FILTER (
        'Table',
        'Table'[BU] = EARLIER ( 'Table'[BU] )
            && 'Table'[Year] > _FirstYear
            && 'Table'[Year] <= EARLIER ( 'Table'[Year] )
    )
VAR _tbl3 =
    ADDCOLUMNS (
        _tbl2,
        "@f", 1 + 'Table'[factor],
        "@adj",
            VAR _f =
                PRODUCTX (
                    WINDOW (
                        1,
                        REL,
                        -1,
                        abs,
                        SUMMARIZE ( _tbl2, 'Table'[BU], 'Table'[Year], 'Table'[factor] ),
                        ORDERBY ( 'Table'[Year] )
                    ),
                    1 + 'Table'[factor]
                )
            RETURN
                ( 'Table'[efficiency] + 'Table'[ Reduction] - 'Table'[sum Reduction] )
                    * IF ( _f, _f, 1 )
    )
RETURN
    IF (
        ISBLANK ( 'Table'[projection] ),
        _BaseProjection * PRODUCTX ( _tbl3, [@f] )
            + SUMX ( _tbl3, [@adj] ),
        'Table'[projection]
    )

View solution in original post

11 REPLIES 11
wdx223_Daniel
Super User
Super User

Output = 
VAR _tbl =
    TOPN (
        1,
        FILTER (
            'Table',
            'Table'[BU] = EARLIER ( 'Table'[BU] )
                && NOT ( ISBLANK ( 'Table'[Projection] ) )
        ),
        'Table'[Year]
    )
VAR _FirstYear =
    MAXX ( _tbl, 'Table'[Year] )
VAR _BaseProjection =
    MAXX ( _tbl, 'Table'[Projection] )
RETURN
    IF (
        ISBLANK ( 'Table'[Projection] ),
        _BaseProjection
            * PRODUCTX (
                FILTER (
                    'Table',
                    'Table'[BU] = EARLIER ( 'Table'[BU] )
                        && 'Table'[Year] > _FirstYear
                        && 'Table'[Year] <= EARLIER ( 'Table'[Year] )
                ),
                1 + 'Table'[Factor]
            ),
        'Table'[Projection]
    )

wdx223_Daniel_0-1677557740952.png

 

Thankyou for this output , things got little complicated as i need adtional column where we add two columns and subtract one other columns . sum reduction is a measure


BUYearprojectionOutputfactorsum Reductionefficiency Reduction
A201953.2753.27131  00
A202051.1351.13091  00
A202157.8257.82309  00
A202255.4155.41486  0-4.3
A2023 53.91866-0.0270.1160-1.7
A2024 55.859730.036-0.2160-16
A2025 57.870680.036-0.79207
A2026 59.954020.036-0.540-2.6
A2027 62.112370.036-0.6340-2
A2028 64.348410.036-0.7060-5
A2029 66.664960.036-0.8860-10
A2030 69.06490.036-1.2460-2
B2019172.63172.629  00
B2020168.54168.5371  00
B2021165.2165.1975  -0.326-0.81
B2022151.13151.1319  -9.513-18
B2023 160.54940.0623-1.122-5.22193-5.64
B2024 170.74060.0635-1.5-6.888-1.62
B2025 178.49030.0454-1.146-11.5-23
B2026 183.8450.03-1.448-4-10.25
B2027 189.36040.03-1.755-3-8
B2028 195.04120.03-1.9950-7.5
B2029 200.89240.03-2.22-0.330
B2030 206.91920.03-2.2200



 want to adjust Output column as below, currently my formula has calculation until 1+factor.

Projection 2023= (Projection of 2022*(1+Factor)+effciency2023 +reduction2023-sum reduction2023)

 

Projection 2024-=(Projection of 2023(calculated in previous step) *(1+Factor) +effciency2024+reduction2024-sum reduction2024)

 

Projection 2025= (Projection of 2024(calculated in previous step) *(1+Factor) +effciency2025+reduction2025-sum reduction2025)and so on until 2030 for each BU

 

from 2019-2022 the data should be same

 

I tried addding efficiency, reduction & subtarcting sum reduction after the 1+factor bracket  but it is just adding directly row to row and not at all subtracting may be because sum reduction is a measure

can you help me in adjusting this fromula in any way? wasted too many days in this.

Hi @wdx223_Daniel is there a possibility of this working out or its not possible in dax? can you suggest ?

is the result correct?

wdx223_Daniel_0-1679903220347.png

Output =
VAR _tbl =
    TOPN (
        1,
        FILTER (
            'Table',
            'Table'[BU] = EARLIER ( 'Table'[BU] )
                && NOT ( ISBLANK ( 'Table'[Projection] ) )
                    && 'Table'[Year] < EARLIER ( 'Table'[Year] )
        ),
        'Table'[Year]
    )
VAR _FirstYear =
    MAXX ( _tbl, 'Table'[Year] )
VAR _BaseProjection =
    MAXX ( _tbl, 'Table'[Projection] )
VAR _tbl2 =
    FILTER (
        'Table',
        'Table'[BU] = EARLIER ( 'Table'[BU] )
            && 'Table'[Year] > _FirstYear
            && 'Table'[Year] <= EARLIER ( 'Table'[Year] )
    )
VAR _tbl3 =
    ADDCOLUMNS (
        _tbl2,
        "@f", 1 + 'Table'[factor],
        "@adj",
            VAR _f =
                PRODUCTX (
                    WINDOW (
                        1,
                        REL,
                        -1,
                        abs,
                        SUMMARIZE ( _tbl2, 'Table'[BU], 'Table'[Year], 'Table'[factor] ),
                        ORDERBY ( 'Table'[Year] )
                    ),
                    1 + 'Table'[factor]
                )
            RETURN
                ( 'Table'[efficiency] + 'Table'[ Reduction] - 'Table'[sum Reduction] )
                    * IF ( _f, _f, 1 )
    )
RETURN
    IF (
        ISBLANK ( 'Table'[projection] ),
        _BaseProjection * PRODUCTX ( _tbl3, [@f] )
            + SUMX ( _tbl3, [@adj] ),
        'Table'[projection]
    )

Thankyou so much for this formula, i converted my Measure into a column and now everything works fine.

yes the output is exactly correct..but my sum reduction is measure which i calculated and idk why its not subtracting it at all ...

maybe the measure can not get the result in the row context of _tbl2

Thankyou so much for this. Perfect

Output = 
VAR _tbl =
    TOPN (
        1,
        FILTER (
            'Table',
            'Table'[BU] = EARLIER ( 'Table'[BU] )
                && NOT ( ISBLANK ( 'Table'[Projection] ) )
                &&'Table'[Index]<EARLIER( 'Table'[Index] )
        ),
        'Table'[Year]
    )
VAR _FirstYear =
    MAXX ( _tbl, 'Table'[Year] )
VAR _BaseProjection =
    MAXX ( _tbl, 'Table'[Projection] )
RETURN
    IF (
        ISBLANK ( 'Table'[Projection] ),
        _BaseProjection
            * PRODUCTX (
                FILTER (
                    'Table',
                    'Table'[BU] = EARLIER ( 'Table'[BU] )
                        && 'Table'[Year] > _FirstYear
                        && 'Table'[Year] <= EARLIER ( 'Table'[Year] )
                ),
                1 + 'Table'[Factor]
            ),
        'Table'[Projection]
    )

small revise, to consider the case that the years with projection value are not consecutive. such as the year 2026 is not blank, the old code will get a wrong value.

BeaBF
Impactful Individual
Impactful Individual

@snaraya Hi!

 

Output =
VAR CurrentRow = 'Table'[Projection]
VAR PrevRow = CALCULATE(
LASTNONBLANK('Table'[Output], 0),
FILTER('Table', 'Table'[Index] < EARLIER('Table'[Index]) && NOT(ISBLANK('Table'[Projection])))
)
VAR Factor = 'Table'[Factor]
RETURN IF(
NOT(ISBLANK(CurrentRow)), CurrentRow * (1 + Factor),
IF(
NOT(ISBLANK(PrevRow)), PrevRow * (1 + Factor),
BLANK()
)
)

 

BBF

I think i confused you ,

 

the output column is what i am getting using the formula mentioned in the post.

 

using your formula i am still getting same values which i am getting in output column of table..

 

values in my output column should be as follows

 

for 2023- Projection of 2022*(1+Factor of 2023)

for 2024- Projection of 2023(calculated in previous step) *(1+Factor of 2024) 

for 2025- Projection of 2024(calculated in previous step) *(1+Factor of 2025) and so on until 2030 for each BU

 

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.

Top Solution Authors