cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Show only values that occur after the first positive value

Hi,

 

I am struggling to find a solution to my problem and have searched the forum for hours trying to peice together a solution. 

 

I have a hypothetical table with 3 columns: Date, BusinessID, Sales. Using DAX, I want only show values from the Sales column that occur after each business' first initial positive Sale value. The first positive Sale acts as a trigger for us to start tracking further data, so I want to ignore all negative Sales values until a positive one occurs, then show all. In the below screenshot, the orange column has the desired behavior. 

 

I need to do this in DAX, because the Sales column is a measure that relies on a date from another table. 

 

Power BI Forum Question.PNG

 

 
2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Super User I
Super User I

Re: Show only values that occur after the first positive value

This is a column since I don't have your data or measure.  No guarantees but you get the idea.

TxnsFromPos = VAR _col = CALCULATE(MIN(TableSale[Date]), TableSale[Sales] > 0 ,ALLEXCEPT(TableSale, TableSale[businessiD]))
RETURN  
   if (_col <= TableSale[Date], TableSale[Sales], BLANK())

 

Could I ask that in future you post your data (not a picture) and any relevant measure code (or pbix).  

Hope it helps.

View solution in original post

Highlighted
Super User IV
Super User IV

Re: Show only values that occur after the first positive value

I am thinking something like the following:

 

Column = 
  VAR __BusinessID = [BusinessID]
  VAR __Date = [Date]
  VAR __Table = FILTER('Table',[BusinessID] = __BusinessID && [Date] <= __Date)
  VAR __FirstPositive = MINX(FILTER(__Table,[Sales] > 0),[Date])
RETURN
  IF(__Date >= __FirstPositive,[Sales],BLANK())

 


---------------------------------------

Putting square pegs in round holes since 1972.

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
Highlighted
Super User I
Super User I

Re: Show only values that occur after the first positive value

This is a column since I don't have your data or measure.  No guarantees but you get the idea.

TxnsFromPos = VAR _col = CALCULATE(MIN(TableSale[Date]), TableSale[Sales] > 0 ,ALLEXCEPT(TableSale, TableSale[businessiD]))
RETURN  
   if (_col <= TableSale[Date], TableSale[Sales], BLANK())

 

Could I ask that in future you post your data (not a picture) and any relevant measure code (or pbix).  

Hope it helps.

View solution in original post

Highlighted
Super User IV
Super User IV

Re: Show only values that occur after the first positive value

I am thinking something like the following:

 

Column = 
  VAR __BusinessID = [BusinessID]
  VAR __Date = [Date]
  VAR __Table = FILTER('Table',[BusinessID] = __BusinessID && [Date] <= __Date)
  VAR __FirstPositive = MINX(FILTER(__Table,[Sales] > 0),[Date])
RETURN
  IF(__Date >= __FirstPositive,[Sales],BLANK())

 


---------------------------------------

Putting square pegs in round holes since 1972.

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Highlighted
Frequent Visitor

Re: Show only values that occur after the first positive value

This worked great! Thanks, Greg! I may have been overthinking it...

Highlighted
Frequent Visitor

Re: Show only values that occur after the first positive value

Thanks! I will share the pbix in the future. good advice!

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors