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
pcowman1
Helper I
Helper I

Row - Calculate Difference from Previous Row

I found this on another post and I think it might be the lead I need but if someone knows another way I'd greatly appreciate it. I am trying to find out if there is a box number missing from a set of numbers. There are more fields in play but I've done Order By in my query and just need to compare if the box number in the current row is 1 different from the previous  (1, 2, 3, 4, 5 not 1, 2, 3, 5, 6). I've changed this already to the two fields I believe are needed. 

 

Index.1 = Index Row

Box No_ = Number to be compared to previous row.

 

Difference =
IF(
'Box Sequence'[Index.1] = 0,
FALSE(),
LOOKUPVALUE(
'Box Sequence'[Box No_],
'Box Sequence'[Index.1],
'Box Sequence'[Index.1]-1)
)
1 ACCEPTED SOLUTION

Hi @pcowman1 ,

We could achieve your desired output with the Dax expression.

Firstly, you need create an Index column in Query Editor and then create the calculated column with the formula below.

Column =
VAR a =
    'Table1'[Box No_]
        - CALCULATE (
            MAX ( 'Table1'[Box No_] ),
            FILTER ( 'Table1', 'Table1'[Index] = EARLIER ( Table1[Index] ) - 1 )
        )
VAR b =
    CALCULATE ( MAX ( 'Table1'[Box No_] ), 'Table1'[Index] = 1 )
RETURN
    IF ( b = 1, "No", IF ( a > 1, "Yes", "No" ) )

Here is the output.

Capture.PNG

Hope this can help you!

In addition, if you have questions with other topic, please create a new thread with a new topic so that the community members who have the same question will find the solution directly.

Best Regards,

Cherry

 

Community Support Team _ Cherry Gao
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

5 REPLIES 5
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @pcowman1 ,

I still have  a little confused about your sceanrio.

If it is convenient, could you share your data sample and your desired output so that we could help further on it.

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Box 10 Missing.PNG

This is what I'm looking for. In Excel it's this formula: =IF(E2=1,"No",IF((E2-E1)>1,"Yes","No"))

 

I have the information sorted by Item, Production Date, Lot, Pallet, Box. I added an Index column in Power BI hoping to use it and do 'when the index is one less than the current index is the box number also one less' - but in M or DAX.

Hi @pcowman1 ,

We could achieve your desired output with the Dax expression.

Firstly, you need create an Index column in Query Editor and then create the calculated column with the formula below.

Column =
VAR a =
    'Table1'[Box No_]
        - CALCULATE (
            MAX ( 'Table1'[Box No_] ),
            FILTER ( 'Table1', 'Table1'[Index] = EARLIER ( Table1[Index] ) - 1 )
        )
VAR b =
    CALCULATE ( MAX ( 'Table1'[Box No_] ), 'Table1'[Index] = 1 )
RETURN
    IF ( b = 1, "No", IF ( a > 1, "Yes", "No" ) )

Here is the output.

Capture.PNG

Hope this can help you!

In addition, if you have questions with other topic, please create a new thread with a new topic so that the community members who have the same question will find the solution directly.

Best Regards,

Cherry

 

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you! That works. I'm going to use it in conjunction with my other 'solution' which was to do a table which did Sum(Quantity) and MAX (Box) and then subtracted one from the other. That gave me which ones to check and then this gives me a quicker reference as to which box is missing. I can put a highlight on the cell. Much appreciated.

Box in Sequence.PNG

I have an additional question with this one - Does anyone know Python visuals? I haven't tried it yet. I used to write Python. Maybe this could be done that way now that they're available as part of the PBI Desktop.

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.