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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register 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])

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.