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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
TK12345
Resolver I
Resolver I

How to get cumulative totals until date in column matrix

Hi there, 

I have a question about a DAX-Measure I would like to make.

What I would like to make is a Matrix, that shows me the amount of stock, untill the date in the LastDate column. So I would like to make a matrix with _KeyArtikel in the rows and LastDate in columns. The value I would like to calculate is: what is the amount of stock I have for the date in LastDate column. So the columns will be 13-07-2023, 13-08-2023, 13-05-2023 and 13-06-2023. For the first column (13-07-2023) I would like the sum of amount for all the dates from start of my calendar to 13-07-2023. So that will be 32.223. My Key_date 2306060 corespondates with 06-06-2023 in my calendar table. Next column (13-08-2023) needs to be sum of amount where my min date is first date in calendar and max date is 13-08-2023 so that will be 62.223. 

I have tried using DatesBetween(date, startdate, enddate) Where startdate is first date of calendar and enddate is max LastDate. But it still does not work. 

Who could help me out?

Expected outcome: 

Artikel 13-7-202313-8-202313-5-202413-6-2024
1a3222360223162351162351



I have the following test-data:

_KeyArtikel_KeyDatumVerwijzingLastDateAmountVerwijzingCategorie
1a20230606StartStock 876StartStock
1a20230606StartStock 876StartStock
1a20230606StartStock 7515StartStock
1a20230606StartStock 9450StartStock
1a20230606StartStock 1530StartStock
1a20230606StartStock 7740StartStock
1a20230606Line 113-7-20232118Production
1a20230607Line 113-7-20232118Production
1a20230607Line 113-8-20232500Production
1a20230608Line 113-8-20232500Production
1a20230609Line 113-8-20232500Production
1a20230610Line 213-8-20232000Production
1a20230610Line 113-8-20232500Production
1a20230611Line 213-8-20232000Production
1a20230612Line 213-8-20232000Production
1a20230613Line 213-8-20232000Production
1a20230614Line 213-8-20232000Production
1a20230617Line 213-8-20232000Production
1a20230618Line 213-8-20232000Production
1a20230619Line 213-8-20232000Production
1a20230620Line 213-8-20232000Production
1a20230621Line 213-8-20232000Production
1a20240314Line 213-5-20249904Production
1a20240314Line 213-5-202416223Production
1a20240314Line 213-5-202413896Production
1a20240314Line 213-5-202413548Production
1a20240314Line 213-5-202414075Production
1a20240319Line 213-5-202411857Production
1a20240326Line 213-5-202411902Production
1a20240402Line 213-6-20248723Production
2 ACCEPTED SOLUTIONS
v-rzhou-msft
Community Support
Community Support

Hi @TK12345 ,

 

I suggest you to try code as below to create a measure.

OutCome = 
IF (
    ISBLANK ( MAX ( 'Table'[LastDate] ) ),
    BLANK (),
    CALCULATE (
        SUM ( 'Table'[Amount] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[_KeyArtikel] ),
            'Table'[LastDate] <= MAX ( 'Table'[LastDate] )
        )
    )
)

Result is as below.

vrzhoumsft_0-1686557774824.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

Got it:

CALCULATE(
    SUM(amount),
    'mdw Fact'[OntvangstOfUitgifte] = "Ontvangst",
    'mdw Fact'[Keydatum] <= SELECTEDVALUE('mdw Fact'[LastDate]),
    ALL('mdw FactBehoeftePlanRegel'[VervaldatumUlc])
)


Thanks for the help

View solution in original post

3 REPLIES 3
v-rzhou-msft
Community Support
Community Support

Hi @TK12345 ,

 

I suggest you to try code as below to create a measure.

OutCome = 
IF (
    ISBLANK ( MAX ( 'Table'[LastDate] ) ),
    BLANK (),
    CALCULATE (
        SUM ( 'Table'[Amount] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[_KeyArtikel] ),
            'Table'[LastDate] <= MAX ( 'Table'[LastDate] )
        )
    )
)

Result is as below.

vrzhoumsft_0-1686557774824.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.

 

Hi Rico

Thanks for your reply. I can get the incomming goods right now. I just forgot the most difficult part. Maybe you know how to do it. In the same table I also have "Sales" (where the LastDate is empty). I do have the sales date in the key. 

What I would like to show in the visual is what is the amount of Sales until the first Max date. So my max date is 13-07-2023 and 13-08-2023 and 13-05-2024. What I would like to see with the sales is how many sales did I have before or on 13-07-2023. In this case it will be -600. How much untill or after 13-08-2023 it will be -600 as well and before or after 13-05-2024 - 1050. I would like to plot that on the same column as the the LastDate in the Matrix. How do I get that. 

When I do Incoming - Outgoing the total is right. But it does not plot the sales on the column of the last date. 

See data: 

1a20240314Line 213-5-202413896Production
1a20240314Line 213-5-202413548Production
1a20240314Line 213-5-202414075Production
1a20240319Line 213-5-202411857Production
1a20240326Line 213-5-202411902Production
1a20240402Line 213-6-20248723Production
1a20230608Sales 1 -100Sales
1a20230609Sales 1 -100Sales
1a20230610Sales 1 -100Sales
1a20230610Sales 1 -100Sales
1a20230611Sales 1 -100Sales
1a20230612Sales 1 -100Sales
1a20240314Sales 1 -150Sales
1a20240314Sales 1 -150Sales
1a20240314Sales 1 -150Sales


Just added 9 sales rows to the data

Got it:

CALCULATE(
    SUM(amount),
    'mdw Fact'[OntvangstOfUitgifte] = "Ontvangst",
    'mdw Fact'[Keydatum] <= SELECTEDVALUE('mdw Fact'[LastDate]),
    ALL('mdw FactBehoeftePlanRegel'[VervaldatumUlc])
)


Thanks for the help

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.