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

Difference Between Oldest and Latest Value

Good Day,

 

I have a very simple problem that I can not solve. I simply want to get the difference between the most recent and the oldest value in a table (as Delta). I want to use the most recent (as Today) and the oldest (as Oldest) and determine the % change: (Oldest - Today)/(Oldest).

Returning values as a scalar turns out to be a nightmare in PBI. Thus I created a workaround to use measures to flag the Lastest and Oldest values in my table. Use a measure to only sum the values that are flagged. Now I get a different problem. I can see the values in my table, but they don't show in my cards (Sum total shows).

 

Below is a screenshot. I also have a link to the PBIX file below. Any help would be much appreciated!


Difference.PNG

@v-frfei-msft 

1 ACCEPTED SOLUTION
tex628
Community Champion
Community Champion

You should be able to calculate it with something along the lines of:

min PLS =
VAR minDate = Calculate(MIN(claendar[{date]) , allselected(calendar))
return 
Calculate( 
sum([amount]) , 
calendar[date] = minDate
)

Connect on LinkedIn

View solution in original post

5 REPLIES 5
Mariusz
Community Champion
Community Champion

Hi @JBI 

Sorry can not see the link, but try the below if it works for you as measures.

first value = 
CALCULATE(
    SELECTEDVALUE( YourTable[Value] ),
    FIRSTDATE( YourTable[Date] )
)

 

last value = 
CALCULATE(
    SELECTEDVALUE( YourTable[Value] ),
    LASTDATE( YourTable[Date] )
)

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski



JBI
Frequent Visitor

This also works. Thanks man I appreciate

tex628
Community Champion
Community Champion

The issue is with the PLS formulas. The only produce a value if the date calendar is filtered to the flagged date. Which it will never be in a card or in a total. 

Add another option in your if statement that checks if
SELECTEDVALUE('Calendar'[Date]) = BLANK() 
This should return true if calculated where there is no date dimension filtering. 


Connect on LinkedIn
JBI
Frequent Visitor

Hi @tex628,

SELECTEDVALUE doesn't work since it requires a column as a parameter and in my example the flag is created by a measure. 

Do you know how to solve this problem without using measures to flag which two columns to use?

 

Thanks!

tex628
Community Champion
Community Champion

You should be able to calculate it with something along the lines of:

min PLS =
VAR minDate = Calculate(MIN(claendar[{date]) , allselected(calendar))
return 
Calculate( 
sum([amount]) , 
calendar[date] = minDate
)

Connect on LinkedIn

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.