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
Liamnorris25
New Member

Adding to cell above in calculated column if condition exists

PowerBI.jpg

 

Hi all, 

 

I am new to PowerBI and need some help with DAX I have already created a formula to do this in excel but am having issues in PowerBI. All suggestions are appreciated.  

 

Here is an image of what I am trying to do: 

 
 

I need to count all intervals that meet a condition and if they do, I want to count how many timestamps in a row this occurs for. 

 

So I need to access the cell in the same calculated column but on cell up. Here is the formula in excel (it is from a large spreadsheet

 

 

From 1->2 (image above)

=IF(PJ4>0,TJ3+1,0)       (PJ is from raw data, TJ is the data # 2 from the image above)

 

 

Again thank you for any help you may have!

 

1 REPLY 1
kentyler
Solution Sage
Solution Sage

Power BI does not support referring to a previous row directly like excel does.

You can work around this.

Add an "Index" column to your data.

In your DAX measure you can use a VAR to store the value
Then use a function like CALCULATE to  access the value where the index equal your stored index - 1

 

VAR cur_index = SELECTEDVALUE(datatable[index])

VAR prev_index = cur_index -1

VAR myValue = CALCULATE(datatable[value],datatable[index] = prev_index)

 





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


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