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
Anonymous
Not applicable

Comparing next row data and calculating MOD

Hi,

 

I am trying to compare the value of Product ID with the next cell in the table and performing some If conditions. But my logic doesn't work.

 

 

link to my file-- https://www.dropbox.com/s/grxqnjtmyczhbdl/Sample%20file.pbix?dl=0

 

Here is my Code

Column = Var CurentPID =Sheet1[Product ID]
Var NextPID=Sheet1[Product ID]+1
Var CurrentNumber =Sheet1[Number]
Var NextNumber=Sheet1[Number]+1

Return
If(Sheet1[Product ID]=LOOKUPVALUE(Sheet1[Product ID],Sheet1[Index],Sheet1[Index]+1),
if(or(CurrentNumber=1,NextNumber=1),"NA",
if(Mod(CurrentNumber,NextNumber)=0,"OK","FALSE"))
)

 

My data:

Product IDNumber
1111110000
111111000
111111000
111111
22222500
22222100
222221
333331

 

 

My output with Excel formula =if(B2=1,"na"IF(and(B2=1,B3=1),"na",IF(MOD(B2,B3)=0,"OK","False")))

((However now in Power BI I also want to put a check to see if the product ID in the next cell is same, if not same then if number is 1 then NA))

 

Product IDNumberOutput
1111110000OK
111111000OK
111111000OK
111111na
22222500OK
22222100OK
222221na
333331na

 

Any help is appreciated!

Thanks,

Tejaswi

 

2 ACCEPTED SOLUTIONS

Hello @Anonymous 

This worked for me on your sample data, give it a try.

Column = 
VAR _PreviousAmount = 
    CALCULATE(
        SUM ( Sheet1[Number] ),
        ALLEXCEPT ( Sheet1, Sheet1[Product ID] ),
        Sheet1[Index] = Sheet1[Index] - 1)
VAR _MOD = MOD(_PreviousAmount,Sheet1[Number])
RETURN
SWITCH ( 
    TRUE(),
    Sheet1[Number] = 1, "na",
    _MOD = 0, "OK",
    "False"
)

View solution in original post

Gotcha, just change it to this:

Column = 
VAR _Index = 'Sheet1'[Index]
VAR _NextAmount = 
    CALCULATE(
        SUM ( 'Sheet1'[Number] ),
        ALLEXCEPT ( 'Sheet1', 'Sheet1'[Product ID] ),
        'Sheet1'[Index] = _Index + 1)
VAR _MOD = IF ( ISBLANK(_NextAmount),0,MOD('Sheet1'[Number],_NextAmount))
Return
SWITCH ( 
    TRUE(),
    'Sheet1'[Number] = 1, "na",
    _MOD = 0, "OK",
    "False"
)

Mod2.jpg 

View solution in original post

11 REPLIES 11

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.