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

Calculating previous row with earlier function

Hello,

 

I have the date, user, value columns. In a date, I can have many users and the value for each user should grow.

I need to know when a value is smaller for a later date. I cannot use index because I have several users the same date so my data will not be ordered. I am trying to use a EARLIER function but it is not working well. Could anyone help me?

 

lipajsal_1-1655454505620.png

 

The code I am using is: 

MAXX(FILTER('Table','Table'[USER]=EARLIER('Table'[USER]) && 'Table[VALUE] <= EARLIER( 'Table[VALUE]),1)
 
Thanks in advance
 
 
1 ACCEPTED SOLUTION

Hi @Anonymous ,

No problem. Here you go

rohit_singh_0-1655472663928.png


You just need to change the variables _curr and _rank and it will work fine.

var _curr = MinVal[Value]

var _rank = MinVal[Rank]
 

Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 🙂

 

 



View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Thanks for your answer Rohit. This solution works for a measure but I need to apply it in a column, for a column all values are 0.

Hi @Anonymous ,

No problem. Here you go

rohit_singh_0-1655472663928.png


You just need to change the variables _curr and _rank and it will work fine.

var _curr = MinVal[Value]

var _rank = MinVal[Rank]
 

Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 🙂

 

 



NickolajJessen
Solution Sage
Solution Sage

This here grants you the lowest future value

NickolajJessen_0-1655457276702.png

Then you can add conditionaly formatting for whatever you are looking to do with it 🙂 

rohit_singh
Solution Sage
Solution Sage

Hi @Anonymous ,

First create a calculated column to calculate rank. This will rank your dates in order by user and will make your calculation very easy. 

rohit_singh_0-1655457009302.png

Rank =

RANKX(
FILTER(MinVal, MinVal[User] = EARLIER(MinVal[User])),
MinVal[Date],
,
ASC,
Dense
)

 

Next, create a measure to flag the row where the value is less than previous row. Since you have created the rank in the previous step, you can simply filter by rank-1 to get previous row.

rohit_singh_1-1655457152534.png

 

ValueFlag =

var _curr = SUM(MinVal[Value])

var _rank = max(MinVal[Rank])

var _prev =
CALCULATE(
SUM(MinVal[Value]),
FILTER(
ALLEXCEPT(MinVal, MinVal[User]),
MinVal[Rank] = _rank-1)
)

var _cmp = if(_prev > _curr , 1 , 0)
RETURN
if(isblank(_prev), 0, _cmp)


Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 🙂

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.