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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
ohkjuns
Frequent Visitor

New row creation with performance value distribution

Hello All,

I need help to calculate speed performance column.

This is raw data example. Goal is to create a new table to calculate average speed performance in each step (days per step).

 

DateStepProduct lot
9/1/20221Lot1
9/2/20222Lot1
9/3/20223Lot1
9/4/20224Lot1
9/1/20221Lot2
9/2/20223Lot2
9/3/20224Lot2
9/1/20221Lot3
9/2/20221Lot3
9/3/20222Lot3
9/4/20224Lot3

 

This is what I am looking for. I could not figure out how to add new steps that are not existing in raw data table (i.e. Lot2 step 2). Also, need to distribute speed performance score evenly. 

Product lotStepDay per step
Lot111
Lot121
Lot131
Lot210.5
Lot220.5
Lot231
Lot312
Lot320.5
Lot330.5

 

I could not figure out solution so far. Could anyone help to get proper result?

Thank you in advance. 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @ohkjuns ,

 

I have updated my code.

New Table = 
VAR _GENERATE =
    GENERATE ( VALUES ( 'Table'[Product lot] ),CALCULATETABLE( VALUES ( 'Table'[Step] ),FILTER('Table','Table'[Step] <> MAX('Table'[Step]) )))
VAR _ADDCOUNT =
    ADDCOLUMNS (
        _GENERATE,
        "Count",
            CALCULATE (
                COUNT ( 'Table'[Product lot] ),
                FILTER (
                    'Table',
                    'Table'[Product lot] = EARLIER ( [Product lot] )
                        && 'Table'[Step] = EARLIER ( [Step] )
                )
            )
    )
VAR _ADD1 =
    ADDCOLUMNS (
        _ADDCOUNT,
        "MAXNOTBLANK",
            MAXX (
                FILTER (
                    _ADDCOUNT,
                    [Product lot] = EARLIER ( [Product lot] )
                        && [Step] <= EARLIER ( [Step] )
                        && [Count] <> 0
                ),
                [Step]
            )
    )
VAR _ADD2 =
    ADDCOLUMNS (
        _ADD1,
        "Days",
            VAR _COUNT2 =
                COUNTAX (
                    FILTER (
                        _ADD1,
                        [Product lot] = EARLIER ( 'Table'[Product lot] )
                            && [MAXNOTBLANK] = EARLIER ( [MAXNOTBLANK] )
                    ),
                    [MAXNOTBLANK]
                )
            VAR _MINBLANK =
                MINX (
                    FILTER (
                        _ADDCOUNT,
                        [Product lot] = EARLIER ( [Product lot] )
                            && [Step] >= EARLIER ( [Step] )
                            && [Count] = 0
                    ),
                    [Step]
                )
            VAR _RETURNCOUNT =
                SUMX (
                    FILTER (
                        _ADD1,
                        [Product lot] = EARLIER ( 'Table'[Product lot] )
                            && [MAXNOTBLANK] = EARLIER ( [MAXNOTBLANK] )
                    ),
                    [Count]
                )
            RETURN
                IF (
                    _COUNT2 = 1,
                    [Count],
                    DIVIDE ( _RETURNCOUNT, _MINBLANK - [MAXNOTBLANK] + 1 )
                )
    )
RETURN
    SUMMARIZE(_ADD2,[Product lot],[Step],[Days])

Result is as below.

RicoZhou_0-1665715142999.png

 

Best Regards,
Rico Zhou

 

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

Hi @ohkjuns ,

 

Here I suggest you to try this code to create a calculated table.

New Table = 
VAR _GENERATE =
    GENERATE ( VALUES ( 'Table'[Product lot] ), VALUES ( 'Table'[Step] ) )
VAR _ADDCOUNT =
    ADDCOLUMNS (
        _GENERATE,
        "Count",
            CALCULATE (
                COUNT ( 'Table'[Product lot] ),
                FILTER (
                    'Table',
                    'Table'[Product lot] = EARLIER ( [Product lot] )
                        && 'Table'[Step] = EARLIER ( [Step] )
                )
            )
    )
VAR _ADD1 =
    ADDCOLUMNS (
        _ADDCOUNT,
        "MAXNOTBLANK",
            MAXX (
                FILTER (
                    _ADDCOUNT,
                    [Product lot] = EARLIER ( [Product lot] )
                        && [Step] <= EARLIER ( [Step] )
                        && [Count] <> 0
                ),
                [Step]
            )
    )
VAR _ADD2 =
    ADDCOLUMNS (
        _ADD1,
        "Count2",
            VAR _COUNT2 =
                COUNTAX (
                    FILTER (
                        _ADD1,
                        [Product lot] = EARLIER ( 'Table'[Product lot] )
                            && [MAXNOTBLANK] = EARLIER ( [MAXNOTBLANK] )
                    ),
                    [MAXNOTBLANK]
                )
            VAR _MINBLANK =
                MINX (
                    FILTER (
                        _ADDCOUNT,
                        [Product lot] = EARLIER ( [Product lot] )
                            && [Step] >= EARLIER ( [Step] )
                            && [Count] = 0
                    ),
                    [Step]
                )
            VAR _RETURNCOUNT =
                SUMX (
                    FILTER (
                        _ADD1,
                        [Product lot] = EARLIER ( 'Table'[Product lot] )
                            && [MAXNOTBLANK] = EARLIER ( [MAXNOTBLANK] )
                    ),
                    [Count]
                )
            RETURN
                IF (
                    _COUNT2 = 1,
                    [Count],
                    DIVIDE ( _RETURNCOUNT, _MINBLANK - [MAXNOTBLANK] + 1 )
                )
    )
RETURN
    SUMMARIZE(_ADD2,[Product lot],[Step],[Count2])

Result is as below.

RicoZhou_0-1665645752620.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@ohkjuns , what is the logic behind 1, .5 and 2

 

The information you have provided is not making the problem clear to me. Can you please explain with an example.

Appreciate your Kudos.

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Logic for values are days per process. For Lot1, step1-3 takes one day per each step, resulting in 1. For lot2, step 1 and 2 take one day so that it has 0.5 score. Lot 3 needs 2 days for step1, which is 2 score. There is no step4 score yet in the table since it is not sure whether process is completed or not so that it is excluded. 

Hope that this clears your question.

Anonymous
Not applicable

Hi @ohkjuns ,

 

I have updated my code.

New Table = 
VAR _GENERATE =
    GENERATE ( VALUES ( 'Table'[Product lot] ),CALCULATETABLE( VALUES ( 'Table'[Step] ),FILTER('Table','Table'[Step] <> MAX('Table'[Step]) )))
VAR _ADDCOUNT =
    ADDCOLUMNS (
        _GENERATE,
        "Count",
            CALCULATE (
                COUNT ( 'Table'[Product lot] ),
                FILTER (
                    'Table',
                    'Table'[Product lot] = EARLIER ( [Product lot] )
                        && 'Table'[Step] = EARLIER ( [Step] )
                )
            )
    )
VAR _ADD1 =
    ADDCOLUMNS (
        _ADDCOUNT,
        "MAXNOTBLANK",
            MAXX (
                FILTER (
                    _ADDCOUNT,
                    [Product lot] = EARLIER ( [Product lot] )
                        && [Step] <= EARLIER ( [Step] )
                        && [Count] <> 0
                ),
                [Step]
            )
    )
VAR _ADD2 =
    ADDCOLUMNS (
        _ADD1,
        "Days",
            VAR _COUNT2 =
                COUNTAX (
                    FILTER (
                        _ADD1,
                        [Product lot] = EARLIER ( 'Table'[Product lot] )
                            && [MAXNOTBLANK] = EARLIER ( [MAXNOTBLANK] )
                    ),
                    [MAXNOTBLANK]
                )
            VAR _MINBLANK =
                MINX (
                    FILTER (
                        _ADDCOUNT,
                        [Product lot] = EARLIER ( [Product lot] )
                            && [Step] >= EARLIER ( [Step] )
                            && [Count] = 0
                    ),
                    [Step]
                )
            VAR _RETURNCOUNT =
                SUMX (
                    FILTER (
                        _ADD1,
                        [Product lot] = EARLIER ( 'Table'[Product lot] )
                            && [MAXNOTBLANK] = EARLIER ( [MAXNOTBLANK] )
                    ),
                    [Count]
                )
            RETURN
                IF (
                    _COUNT2 = 1,
                    [Count],
                    DIVIDE ( _RETURNCOUNT, _MINBLANK - [MAXNOTBLANK] + 1 )
                )
    )
RETURN
    SUMMARIZE(_ADD2,[Product lot],[Step],[Days])

Result is as below.

RicoZhou_0-1665715142999.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

It is working good. Thank you for beautiful code. Let me take time to digest details further. 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.