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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
JLET
New Member

Calculate Sum with Filter is almost doubling results

Using the below table I am trying to calculate a filed to refelct the privious recorded value with the restrictions set by the filter. For some reson the value that returns is basically double what I expect.

 

JLET_0-1675864816994.png

 

Previous Meter kwh = CALCULATE(


SUM('TEST Electric Meters Summerized'[Meter kwh]),

FILTER(

'TEST Electric Meters Summerized',

'TEST Electric Meters Summerized'[Attribute]=EARLIER('TEST Electric Meters Summerized'[Attribute])

&&'TEST Electric Meters Summerized'[Datetime Prior]<EARLIER('TEST Electric Meters Summerized'[DataTimestamp])

&&'TEST Electric Meters Summerized'[DataTimestamp] >= EARLIER('TEST Electric Meters Summerized'[Datetime Prior])))
 
 
 
Datetime Prior =
CALCULATE(MAX('TEST Electric Meters Summerized'[DataTimestamp]),
 
FILTER(
'TEST Electric Meters Summerized',
'TEST Electric Meters Summerized'[DataTimestamp] < EARLIER('TEST Electric Meters Summerized'[DataTimestamp])))
 
1 REPLY 1
v-stephen-msft
Community Support
Community Support

Hi @JLET ,

 

In the filters, 'TEST Electric Meters Summerized'[Attribute]=EARLIER('TEST Electric Meters Summerized'[Attribute]) is grouped according to Attribute.

What do below two filters do?

&&'TEST Electric Meters Summerized'[Datetime Prior]<EARLIER('TEST Electric Meters Summerized'[DataTimestamp])
&&'TEST Electric Meters Summerized'[DataTimestamp] >= EARLIER('TEST Electric Meters Summerized'[Datetime Prior])))

18.png

 

And if there's no order internally for records in table when you want to get previous row. You have to add an index column in your table. Please refer to

Solved: How to get previous row value for text column. - Microsoft Power BI Community

 

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors