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

Calculate delta per row

Hi all,

 

I'm trying to do something which should be pretty basic but I can't seem to wrap my head around how to. Simply, I would like to automate the Delta column from the below example:

ProdTest CaseValueDelta from previous Sim
aDefault50
aSim261
aSim35-1
bDefault30
bSim285
bSim37-1
cDefault40
cSim262
cSim382

 

My source data selects from the latest file in a folder and the issue is that each file can have a different number of Test Cases( e.g. my example here has 3 cases per product, another file could have 15 per product) and I want to be able to dynamically adjust rather than nest IF or use Switch.

 

Any suggestions? Thanks!

1 ACCEPTED SOLUTION
FarhanAhmed
Community Champion
Community Champion

I think you need to have a index/sequence number on how to calculate delta here. means

 

default is 1

Sim2 is 2

Sim3 is 3

 

 

one way is you can create it by  Group By in power query for Test Cast and operation shoud be "All Rows"

FarhanAhmed_0-1655372767395.png

 

Then add index on it

 

FarhanAhmed_1-1655372824641.png

 

 

Expand the table again

FarhanAhmed_2-1655372869740.png

 

Create a calculated column like this

 

_Delta = Var P = delta[Prod]
Var v = delta[Value]
Var i = delta[Index]
 RETURN

 IF ( delta[Index]=0,0, v- CALCULATE(MAX(delta[Value]),FILTER(delta,delta[Prod]=P &&  delta[Index]=i-1 )))

 

 

 

 







Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
FarhanAhmed
Community Champion
Community Champion

I think you need to have a index/sequence number on how to calculate delta here. means

 

default is 1

Sim2 is 2

Sim3 is 3

 

 

one way is you can create it by  Group By in power query for Test Cast and operation shoud be "All Rows"

FarhanAhmed_0-1655372767395.png

 

Then add index on it

 

FarhanAhmed_1-1655372824641.png

 

 

Expand the table again

FarhanAhmed_2-1655372869740.png

 

Create a calculated column like this

 

_Delta = Var P = delta[Prod]
Var v = delta[Value]
Var i = delta[Index]
 RETURN

 IF ( delta[Index]=0,0, v- CALCULATE(MAX(delta[Value]),FILTER(delta,delta[Prod]=P &&  delta[Index]=i-1 )))

 

 

 

 







Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!

Proud to be a Super User!




Thanks for your help @FarhanAhmed, this worked perfectly.

tamerj1
Super User
Super User

@GBKYE2 
Do you have any index or date column or this is just your data? I mean are the values listed in the Test Case column are real? Like starting from "Default" then "Sim1", "Sim2", Sim3', "Sim4, ...... and so on?

Hi @tamerj1, no date column but I followed @FarhanAhmed's advice above and added an index per simulation in Power Query and was able to iterate off that.

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.