Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
MorePowerBI
Helper II
Helper II

Self-referencing calculated column to generated ascending number sequence that repeats

Hello,

 

I'm trying to recreate the highlighted [Dispense #] column in the JMP table.

MorePowerBI_0-1658436058833.png

 

The column generates an ascending number sequence for each consecutive row with [ValueName] = "Dispense Weight Chec". The number sequence restarts at 1 if the previous row's value for [ValueName]<>"Dispense Weight Chec".

 

The JMP code for the column is:
If( :ValueName == "Dispense Weight Chec", If( Lag( :ValueName ) != "Dispense Weight Chec", 1, Lag( :Dispense # ) + 1 )

 

Not sure if PBI allows calculated columns to self-reference its previous row's value, but that seems to be what I need to generate this column. 

 

Here's the sample dataset:

SiteProcessNameEQNumberValueNameValueCreatedDateTimeWC TypeWC ResultDispense #
SANTED StationEQ-901848-004Dispense Weight Chec3.5996093757/17/2022 12:50Tip Change 1
SANTED StationEQ-901848-004DispenseTipXOffset-0.0620823617/17/2022 12:53Tip Change  
SANTED StationEQ-901848-004DispenseTipYOffset-0.3642040797/17/2022 12:53Tip Change  
SANTED StationEQ-901848-004DispenseTipZOffset1.6372065547/17/2022 12:53Tip Change  
SANTED StationEQ-901848-004DispenseTipXOffset-0.1363512587/17/2022 12:59Tip Change  
SANTED StationEQ-901848-004DispenseTipYOffset-0.3996126357/17/2022 12:59Tip Change  
SANTED StationEQ-901848-004DispenseTipZOffset0.9583350427/17/2022 12:59Tip Change  
SANTED StationEQ-901848-004DispenseTipXOffset-0.1291977477/17/2022 13:02Tip Change  
SANTED StationEQ-901848-004DispenseTipYOffset-0.3084970127/17/2022 13:02Tip Change  
SANTED StationEQ-901848-004DispenseTipZOffset1.2000350957/17/2022 13:02Tip Change  
SANTED StationEQ-901848-004Dispense Weight Chec2.8994140637/17/2022 13:02Tip Change 1
SANTED StationEQ-901848-004Dispense Weight Chec3.9003906257/17/2022 13:02Tip Change 2
SANTED StationEQ-901848-004Dispense Weight Chec4.0996093757/17/2022 13:02Tip Change 3
SANTED StationEQ-901848-004Dispense Weight Chec3.9003906257/17/2022 13:02Tip Change 4
SANTED StationEQ-901848-004Dispense Weight Chec3.7998046887/17/2022 13:02Tip Change 5
SANTED StationEQ-901848-004Dispense Weight Chec4.2001953137/17/2022 13:03Tip Change 6
SANTED StationEQ-901848-004Calculated Flow Rate17.533384327/17/2022 13:03Tip Change  
SANTED StationEQ-901848-004Dispense Weight Chec4.0996093757/17/2022 13:14InlinePass1
SANTED StationEQ-901848-004Dispense Weight Chec3.9003906257/17/2022 13:14InlinePass2
SANTED StationEQ-901848-004Dispense Weight Chec4.2001953137/17/2022 13:14InlinePass3
SANTED StationEQ-901848-004Dispense Weight Chec47/17/2022 13:14InlinePass4
SANTED StationEQ-901848-004Dispense Weight Chec4.2001953137/17/2022 13:15InlinePass5
SANTED StationEQ-901848-004Calculated Flow Rate17.895080577/17/2022 13:15Inline  
SANTED StationEQ-901848-004Dispense Weight Chec3.8994140637/17/2022 13:25InlinePass1
SANTED StationEQ-901848-004Dispense Weight Chec4.1005859387/17/2022 13:25InlinePass2
SANTED StationEQ-901848-004Dispense Weight Chec47/17/2022 13:25InlinePass3
SANTED StationEQ-901848-004Dispense Weight Chec47/17/2022 13:26InlinePass4
SANTED StationEQ-901848-004Dispense Weight Chec4.0996093757/17/2022 13:26InlinePass5
SANTED StationEQ-901848-004Calculated Flow Rate17.946079257/17/2022 13:26Inline  

 

1 ACCEPTED SOLUTION
vapid128
Solution Specialist
Solution Specialist

I create a Line Number to rank this one.
image.png

 

Rank1 =
IF('Table (3)'[ValueName]="Dispense Weight Chec",
    RANKX(
        FILTER('Table (3)','Table (3)'[ValueName]<>"Dispense Weight Chec"),
        'Table (3)'[LineNumber],
        ,ASC),
    BLANK()
)
 
Rank2 =
IF('Table (3)'[ValueName]="Dispense Weight Chec",
    RANKX(
        FILTER('Table (3)',[Rank1]=EARLIER('Table (3)'[Rank1])),
        [LineNumber],
        ,ASC
    ),
    BLANK()
)

View solution in original post

6 REPLIES 6
vapid128
Solution Specialist
Solution Specialist

image.png

 

It is all 13:02, Why there is 1 2 3 4 5?

vapid128
Solution Specialist
Solution Specialist

I create a Line Number to rank this one.
image.png

 

Rank1 =
IF('Table (3)'[ValueName]="Dispense Weight Chec",
    RANKX(
        FILTER('Table (3)','Table (3)'[ValueName]<>"Dispense Weight Chec"),
        'Table (3)'[LineNumber],
        ,ASC),
    BLANK()
)
 
Rank2 =
IF('Table (3)'[ValueName]="Dispense Weight Chec",
    RANKX(
        FILTER('Table (3)',[Rank1]=EARLIER('Table (3)'[Rank1])),
        [LineNumber],
        ,ASC
    ),
    BLANK()
)

You wizard!

MorePowerBI
Helper II
Helper II

Still looking to see if anyone can help out a fellow Power BI addict

amitchandak
Super User
Super User

@MorePowerBI , You can not self-reference, You need to think cumulative. You have to use logic earlier

 

example

Continuous streak: https://youtu.be/GdMcwvdwr0o

https://community.powerbi.com/t5/Community-Blog/Power-BI-Continuous-Streak-With-One-Day-Break/ba-p/1...

 


Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

@amitchandak Yeah I figured I'll need to incorporate EARLIER() somehow. Here's the link to the files: OneDrive 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

Check out the August 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.