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
Anonymous
Not applicable

Measure to calculate current value minus previous row for a specific device

Hey!

 

I have the same problem for some time now that I really can't solve. I am doing a calculation to calculate the total energy,

 

I have following as example:

I have a column with an accumulative TotalEnergy for every device, I have the devices as dirfferent name, Index and I made a Rank with following formula (Where EndUtc is Date and time)

Rank = RANKX(FILTER(Data, Data[Device] = EARLIER(Data[Device])), Data[EndUtc],,ASC)
 
I wanna make a calculation NEWENERGYPERDAY: as for device A, 365-364 = 1, 364-364=0 etc, for every row. 

 

 

Capture.PNG

 

I have tried many different calculations, as for example: 

 

NewEnergyPer300s_kWh =
VAR minIndx = CALCULATE (
MAX ( Data[Index] ),
ALLEXCEPT ( Data, Data[Device] ),
Data[Index] < EARLIER (Data[Index] )
)
 
RETURN
 
IF (
ISBLANK ( minIndx ),
BLANK (),
Data[TotalEnergy_kWh]
    - CALCULATE (
               SUM ( Data[TotalEnergy_kWh] ),
                   Data[Index] = minIndx,
                       ALL ( Data )
)
)

 

which worked fine, except that I am getting not enough memory capacity, which is weird cause I don't even have too much data, and when I find other formulas and using function EARLIER I get the same issue evrytime, is it possible to write this formula or similar as a measure and not a column?

 

And also if there are any better way to write the calculation that will be better for the memory capcity?

 

Thanks! Feeling a bit lost with this issue. 

 

Kind regards

2 ACCEPTED SOLUTIONS

Hi again,

Can you share your file? I am sorry but I think that I have overlooked some important facts in original post, but if you have created a Index column that increases with every new entry per device you should be able to use this calculated column. And perhaps you do not have to use the device varible at all (i.e. if i Index contains unique values)

EnergyPerDay =
VAR device = Data[Device]    // could be skipped
VAR ind = Data[Index]
VAR preInd= ind-1
VAR energyPreDate  = 
  SUMX(
    FILTER(
      Data,
      Data[Index] = preInd 
&& Data[Device] = device // could also be skipped ), Data[TotalEnergy_kWh] ) RETURN Data[TotalEnergy_kWh] - energyPreDate



Best regars,

Kristjan

 

View solution in original post

v-cherch-msft
Employee
Employee

Hi @Anonymous

 

You may try to create below measures:

NextValue =
CALCULATE (
    SUM ( Data[TotalEnergy_kWh] ),
    FILTER ( ALLEXCEPT ( Data, Data[Device] ), Data[Rank] = MAX ( Data[Rank] ) - 1 )
)
NEWENERGYPERDAY =
IF (
    ISBLANK ( [NextValue] ),
    BLANK (),
    SUM ( Data[TotalEnergy_kWh] ) - [NextValue]
)

1.png

 

 

Regards,

Cherie

Community Support Team _ Cherie Chen
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

12 REPLIES 12

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.