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
OscarSuarez10
Helper III
Helper III

Fitst Negative number before the first positive number

Hello How can I get the first negative number  for each ID and Task before the first positive number like in the following table?

 

ID: 0 TASK: 1 First negative number before first positive number = -20

ID: 11 TASK: 3  First negative number before first positive number = -10

ID: 5 TASK: 2  First negative number before first positive number = -8

 

IDTASKPROD
01-100
01-50
01-20
0110
0140
01100
113-50
113-10
11320
113-2
113-10
11310
52-50
52-8
5220
52-5
5230

 

1 ACCEPTED SOLUTION
Nathaniel_C
Super User
Super User

Hi @OscarSuarez10 ,

You will need to go to Power Query and add a index column.

Then

Get pos =
VAR _getfirstpos =
    CALCULATE (
        MIN ( Neg[Index] ),
        FILTER ( ALLEXCEPT ( Neg, Neg[ID], Neg[TASK] ), Neg[PROD] > 0 )
    )
VAR _getfirstneg =
    CALCULATE (
        MAX ( Neg[PROD] ),
        FILTER ( ALLEXCEPT ( Neg, Neg[ID], Neg[TASK] ), Neg[Index] < _getfirstpos )
    )
RETURN
    _getfirstneg

to get this get pos.PNG

 

 
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel





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
Nathaniel_C
Super User
Super User

Hi @OscarSuarez10 ,

You will need to go to Power Query and add a index column.

Then

Get pos =
VAR _getfirstpos =
    CALCULATE (
        MIN ( Neg[Index] ),
        FILTER ( ALLEXCEPT ( Neg, Neg[ID], Neg[TASK] ), Neg[PROD] > 0 )
    )
VAR _getfirstneg =
    CALCULATE (
        MAX ( Neg[PROD] ),
        FILTER ( ALLEXCEPT ( Neg, Neg[ID], Neg[TASK] ), Neg[Index] < _getfirstpos )
    )
RETURN
    _getfirstneg

to get this get pos.PNG

 

 
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel





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

Proud to be a Super User!




Nathaniel_C
Super User
Super User

Hi @OscarSuarez10 ,

When you say the  first negative number, are you looking for the highest negative number?

Nathaniel





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

Proud to be a Super User!




Hi @Nathaniel_C  no, I am looking for the first negative number that appears immediatly before the first positive number according to the Product column

 

Ok, I figured that.  How does that solution work for you? Nathaniel

 





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

Proud to be a Super User!




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