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
andry456
Regular Visitor

Count if previous value is bigger than a number

Hi everyone,

I'm having troubles trying to make a new measure in PowerBi. I have a column regarding of instantaneous energy production value and I'd like to make a counter of any daily stop.

This is the idea: if the value of N row is less than X AND the value of the previous row (N-1) is bigger than X, the measure must return "1"; instead, it will return "0".

I tried using COUNT formula without success.

Can you plase give me an hand?

 

Thank you!

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

@andry456 ,

 

Suppose the X is 20, you could create a calculate column using dax below:

Flag = 
VAR X = 20
VAR Current_Value = 'Table'[Value]
VAR Previous_Index = 'Table'[Index] - 1
VAR Previous_Value = CALCULATE(MAX('Table'[Value]), FILTER('Table', 'Table'[Index] = Previous_Index))
RETURN
IF(X > Current_Value && X < Previous_Value, 1, 0)

Capture.PNG 

 

Community Support Team _ Jimmy Tao

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

2 REPLIES 2
v-yuta-msft
Community Support
Community Support

@andry456 ,

 

Suppose the X is 20, you could create a calculate column using dax below:

Flag = 
VAR X = 20
VAR Current_Value = 'Table'[Value]
VAR Previous_Index = 'Table'[Index] - 1
VAR Previous_Value = CALCULATE(MAX('Table'[Value]), FILTER('Table', 'Table'[Index] = Previous_Index))
RETURN
IF(X > Current_Value && X < Previous_Value, 1, 0)

Capture.PNG 

 

Community Support Team _ Jimmy Tao

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

Anonymous
Not applicable

Hi,

 

For the sake of this Demo, I would assume your X=50 

 

Calculated Column:= 
VAR PreviousRow = TOPN (1,FILTER ( Table1, Table1[Column1] < EARLIER ( Table1[Column1] ) && Table1[Column2] = EARLIER ( Table1[Column2] )), [Column1], DESC)
RETURN IF( AND(Table[ColumnA]>50,Table[ColumnB]>50),1,0)

Consider two columns from your table as [Column1] && [Column2].

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.