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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
roelf
Helper II
Helper II

Cumulative per day per person

Hi

 

My dashboard is to measure the production of KG's packed, per person, per day in a factory.

 

My data looks like this:

DatePersonReal Weight
01-Jan-22Person A1
01-Jan-22Person A1.5
01-Jan-22Person A1
01-Jan-22Person A1.6
01-Jan-22Person A1
01-Jan-22Person B3.5
01-Jan-22Person B3
01-Jan-22Person B1.5
01-Jan-22Person B2
02-Jan-22Person A1.5
02-Jan-22Person A1
02-Jan-22Person A1
02-Jan-22Person A0.5
02-Jan-22Person B1
02-Jan-22Person B2

 

I Need to get it as follows:

 

DatePersonReal WeightCumulative Weight
01-Jan-22Person A11
01-Jan-22Person A1.52.5
01-Jan-22Person A13.5
01-Jan-22Person A1.65.1
01-Jan-22Person A16.1
01-Jan-22Person B3.53.5
01-Jan-22Person B36.5
01-Jan-22Person B1.58
01-Jan-22Person B210
02-Jan-22Person A1.51.5
02-Jan-22Person A12.5
02-Jan-22Person A13.5
02-Jan-22Person A0.54
02-Jan-22Person B11
02-Jan-22Person B23

 

I then have a futher requirement, where I need to know how much was below and how much over 4 KG.

 

So my table needs to expand to this

DatePersonReal WeightCumulative WeightBelow 4Above 4
01-Jan-22Person A111 
01-Jan-22Person A1.52.51.5 
01-Jan-22Person A13.51 
01-Jan-22Person A1.65.10.51.1
01-Jan-22Person A16.1 1
01-Jan-22Person B3.53.53.5 
01-Jan-22Person B36.50.52.5
01-Jan-22Person B1.58 1.5
01-Jan-22Person B210 2
02-Jan-22Person A1.51.51.5 
02-Jan-22Person A12.51 
02-Jan-22Person A13.51 
02-Jan-22Person A0.540.5 
02-Jan-22Person B111 
02-Jan-22Person B232 

 

I have tried about 5 different ways that I could see on the forum, so thanks to those who's answered a similar problem. I have however not found one that gives me the answer I require.

 

If any of you can assist, it will be much appreciated !

 

Thanks

Roelf

 

 

 

 

 

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @roelf ,

According to your description, here's my solution.

Add an index column in Power Query, then create three calculated columns.

Cumulative Weight =
SUMX (
    FILTER (
        'Table',
        'Table'[Date] = EARLIER ( 'Table'[Date] )
            && 'Table'[Person] = EARLIER ( 'Table'[Person] )
            && 'Table'[Index] <= EARLIER ( 'Table'[Index] )
    ),
    'Table'[Real Weight]
)
Above 4 =
VAR _Cum =
    MAXX (
        FILTER (
            'Table',
            'Table'[Date] = EARLIER ( 'Table'[Date] )
                && 'Table'[Person] = EARLIER ( 'Table'[Person] )
                && 'Table'[Cumulative Weight] > 4
                && 'Table'[Cumulative Weight] < EARLIER ( 'Table'[Cumulative Weight] )
        ),
        'Table'[Cumulative Weight]
    )
RETURN
    IF (
        [Cumulative Weight] > 4,
        [Cumulative Weight]
            - IF ( _Cum = BLANK (), 4, _Cum )
    )
Below 4 =
IF (
    [Cumulative Weight] < 4,
    'Table'[Real Weight],
    IF (
        'Table'[Real Weight] - 'Table'[Above 4] = 0,
        BLANK (),
        'Table'[Real Weight] - 'Table'[Above 4]
    )
)

Get the correct result.

vkalyjmsft_0-1666251521450.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

4 REPLIES 4
roelf
Helper II
Helper II

Thank you all for your suggestions - they all worked 100%

What I ended up using:

- Sorted the data in the Power Query

- Then added an index

- Then used the formula given to get the cumulative amount

I have also checked out other examples which suggesting using "RANKX" as a method instead of adding an index column - not sure which is better. I personally preferred adding an index in the query so that I am sure all rows have values.

 

Thanks again all - much appreciated !!

v-yanjiang-msft
Community Support
Community Support

Hi @roelf ,

According to your description, here's my solution.

Add an index column in Power Query, then create three calculated columns.

Cumulative Weight =
SUMX (
    FILTER (
        'Table',
        'Table'[Date] = EARLIER ( 'Table'[Date] )
            && 'Table'[Person] = EARLIER ( 'Table'[Person] )
            && 'Table'[Index] <= EARLIER ( 'Table'[Index] )
    ),
    'Table'[Real Weight]
)
Above 4 =
VAR _Cum =
    MAXX (
        FILTER (
            'Table',
            'Table'[Date] = EARLIER ( 'Table'[Date] )
                && 'Table'[Person] = EARLIER ( 'Table'[Person] )
                && 'Table'[Cumulative Weight] > 4
                && 'Table'[Cumulative Weight] < EARLIER ( 'Table'[Cumulative Weight] )
        ),
        'Table'[Cumulative Weight]
    )
RETURN
    IF (
        [Cumulative Weight] > 4,
        [Cumulative Weight]
            - IF ( _Cum = BLANK (), 4, _Cum )
    )
Below 4 =
IF (
    [Cumulative Weight] < 4,
    'Table'[Real Weight],
    IF (
        'Table'[Real Weight] - 'Table'[Above 4] = 0,
        BLANK (),
        'Table'[Real Weight] - 'Table'[Above 4]
    )
)

Get the correct result.

vkalyjmsft_0-1666251521450.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

 

truptis
Community Champion
Community Champion

Hi @roelf ,

For cumulative weight try this:

Result= SUMX (

    FILTER (

        ALLSELECTED ( tablename[Date] ),

        Tablename[Date] <= MAX ( tablename[Date] )

    ),

    [Realweight]

)

 

@roelf -> please hit the thumbs up & mark it as a solution if it helps you. Thanks.

amitchandak
Super User
Super User

@roelf , Add an index column in power query  first and then try a new column

 

cumm  = sumx(filter(Table, [Person] = earlier([Person]) && [Index] <= earlier([index]) ), [Weight])

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 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.

October NL Carousel

Fabric Community Update - October 2024

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