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
kressb
Helper V
Helper V

Very simple calculation question

I have one Table with 3 columns in PowerBI. I am trying to make a calculated column - "PrevNumber"

kressb_0-1643909153234.png

 

PrevUniqueID will always have a match in the UniqueID column of a different Row.

Goal is to pull the Number column/value for whichever Row has a UniqueID that matches the PrevUniqueID.

I am trying this formula:

CALCULATE(
sum(Table[Number]),
Filter(Table,Table[PrevUniqueID]=Earlier(Table[UniqueID]))
 
There are no other tables or columns. Just this. 
I'm not getting the correct answer. This is what was returned:
kressb_1-1643909192908.png

Any ideas?

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @kressb ,

 

Try this code to create a calculated column.

PreviousMonthNumber =
VAR _PreMonthUniqueID =
    CALCULATE (
        SUM ( 'Table'[Number] ),
        FILTER ( 'Table', 'Table'[UniqueID] = EARLIER ( 'Table'[PreMonthUniqueID] ) )
    )
RETURN
    _PreMonthUniqueID + 0

Result is as below.

1.png

 

Best Regards,
Rico Zhou

 

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

4 REPLIES 4
v-rzhou-msft
Community Support
Community Support

Hi @kressb ,

 

Try this code to create a calculated column.

PreviousMonthNumber =
VAR _PreMonthUniqueID =
    CALCULATE (
        SUM ( 'Table'[Number] ),
        FILTER ( 'Table', 'Table'[UniqueID] = EARLIER ( 'Table'[PreMonthUniqueID] ) )
    )
RETURN
    _PreMonthUniqueID + 0

Result is as below.

1.png

 

Best Regards,
Rico Zhou

 

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

 

sirlanceohlott
Advocate III
Advocate III

Hey there, 

EnterpriseDNA has a great writeup on how to achieve this, you can check it out here: https://forum.enterprisedna.co/t/previous-row-value/9789

@sirlanceohlott thanks for the response!
I had been thinking maybe I need indexing.

I thought I could get around it if I could just figure out why the formula is essentially pulling backwards (Dec 2021 is pulling from Jan 2022, instead of having Jan 2022 pulling from Dec 2021). but maybe indexing is really the only answer.. 

@kressb you're welcome! 

 

Yeah, I know it's a little frustrating, but I believe the indexing will help with what you are trying to achieve. I've had similar challenges where indexing was one of the ways to get it functioning as I intended.

 

Best of luck as you continue on, others might have some different solutions too!

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