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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Giancarlo1977
Frequent Visitor

Calculate new value based on previous on same colum

Hi,

 

I am running a project and what I am trying to do is to calculate a Planned Repair based on StringW and UR (Under Repair)

 

StringW = Demand which is different every week

AV = Current Total Capability (coming from system)

UR = Current Under Repair (coming from system)

RTG = Ready to Go : AV-UR

 

StringWx = Is my input which is the weekly demand

AV = Is a fix number and it is my current total capability

UR_x = After the starting number and based on Planned Repair then this number will be recalculated and change over week

RTG_x = After the starting number and based on Planned Repair this number will be recalculated and change over week

 

I am doing this in excel by creating several column for each week like the example below

 

ToolCode

String W1

String W2

String W3

String W4

AV 

UR_1

RTG_1

Planned Repair_1

UR_2

RTG_2

Planned Repair_2

UR_3

RTG_3

Planned Repair_3

UR_4

RTG_4

Planned Repair_4

aaa

40

38

42

44

41

3

38

1

40

0

1

40

1

0

41

0


The formula that I am using in excel to calculate the Planned Repair_1 is:

 

=IF(UR_1=0,0,IF(RTG_1>=StringW1,0,IF(StringW1>(UR_1+RTG_1),UR_1,MIN(UR_1,ABS(RTG_1-StringW1)))))

 

For the following week I have recalculated the UR_2 = UR_1-Planner Repair_1 and RTG_2 = AV-UR_1.

Therefore the new Planned Repair_2 will use the same formual but it will consider UR_2 and RTG_2

 

Planner Repair_2 = =IF(UR_2=0,0,IF(RTG_2>=StringW2,0,IF(StringW2>(UR_2+RTG_2),UR_2,MIN(UR_2,ABS(RTG_2-StringW2)))))

 

And like this for all weeks in different column (which is difficult to see)

 

I am not good in excel so that is the only way I found 

 

I would like to have same results in 1 column in Power BI since my project is automated in PowerBI so if I can figure out the correct way it will by automatically refreshed giving me everytime the new plan and it is easier to monitor

 

So I am trying to find a way to calculate the following columns:

 

Planned Repair

New UR

New RTG

 

ToolCodeWeekNameString per weekAVUR_1RTG_1Planned Repair (Calculated Column)New UR(Calculated Column)New RTG(Calculated Column)
aaaa140413382338
aaaa238413380140
aaaa342413381140
aaaa444413380041

Really appreciate all your support

Thanks

2 REPLIES 2
v-kongfanf-msft
Community Support
Community Support

Hi @Giancarlo1977 ,

 

You can try below formula to created Planned Repair, New UR, New RTG calculated column:

Planned Repair = 
VAR CurrentWeek = 'Table'[WeekName]
VAR UR = 'Table'[UR_1]
VAR RTG = 'Table'[RTG_1]
VAR StringW = 'Table'[String per week]
RETURN
IF(
    UR = 0, 0,
    IF(
        RTG >= StringW, 0,
        IF(
            StringW > (UR + RTG), UR,
            MIN(UR, ABS(RTG - StringW))
        )
    )
)
New UR = 
VAR CurrentWeek = 'Table'[WeekName]
VAR PrevWeek = CurrentWeek - 1
VAR PrevUR = CALCULATE(
    MAX('Table'[UR_1]),
    FILTER('Table', 'Table'[WeekName] = PrevWeek)
)
VAR PrevPlannedRepair = CALCULATE(
    MAX('Table'[Planned Repair]),
    FILTER('Table', 'Table'[WeekName] = PrevWeek)
)
RETURN
PrevUR - PrevPlannedRepair
New RTG = 
'Table'[AV] - 'Table'[New UR]

vkongfanfmsft_0-1717378794871.png

Best Regards,
Adamk Kong

 

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

Hi,

 

Thanks for your reply but unfortunately the formula is not working for me.

 

When I run it I have the following value:

 

 

WeekString per weekAVURRTGPlanned RepairNew UR
142405355 
2304053500
3244053505
4184053505
5444053555
6924053550

 

The value hilighted in bolt are not correct (based on what I am looking for)

The Planned Repair in week 5 and week 6 should be 0 because the New UR from Week 2 till Week 6 should always be 0 since I have repaired all 5 in week 1.

 

So since in week 1 my Planned Repair is 5 my new UR will be 0 and RTG will be 40. So the new Planned Repair formula for the following weeks should consider what happened in previous weeks

 

I hope this is clear and I appreciate your help

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.