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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
16511151454
New Member

Cumulative sum of a measure over two dimensions with missing values

Hi,

 

I'm trying to create a cumulative sum of a measure over two dimensions and the measure has some missing values.

I have successfully created a simple cumulative sum over one dimension but with some missing values it fails.

 

The data:

PeriodPartnerCategoryAmount
2021 Q1JamesPayment12
2021 Q2JamesPayment14
2021 Q4JamesPayment23
2021 Q4JamesObservation15
2022 Q2JamesPayment8
2021 Q1NellyPayment8
2021 Q2NellyPayment15
2021 Q2NellyObservation23
2021 Q3NellyPayment62
2021 Q3NellyObservation45
2021 Q4NellyPayment15
2022 Q1NellyPayment48
2022 Q1NellyObservation45
2022 Q2NellyPayment12
2021 Q1MarkPayment53
2021 Q1MarkObservation74
2021 Q2MarkPayment58
2021 Q2MarkObservation55
2021 Q4MarkPayment65
2021 Q4MarkObservation23
2022 Q1MarkPayment22
2022 Q1MarkObservation56
2022 Q2MarkPayment58
2022 Q2MarkObservation45

 

The measure:

Payment = CALCULATE(SUM('Table'[Amount]), FILTER('Table', 'Table'[Category] = "Payment"))
 
Cumulative payment over the periods work:
Cumulative Payment =
    CALCULATE(
        [Payment],
        FILTER(
            ALLSELECTED('Table'),
            'Table'[Period] <= MAX('Table'[Period])
        ),
        VALUES('Table'[Partner])
    )
 
 
 As you can see there are some missing values (e.g., James does not have a payment in 2021Q3):
16511151454_1-1728058535298.png

The chart by Period and Partner is wrong:

16511151454_0-1728058451683.png

 

How can I create a measure which fills the blanks? I'd like to obtain the following:

16511151454_2-1728058716369.png

 

 

Thanks a lot for the help!

 
7 REPLIES 7
Anonymous
Not applicable

Hi @16511151454 ,

 

I think the cause of the problem is that "James" has no record of "2021 Q3" in your metadata, which results in blank lines, and blank lines are not calculated. I recommend creating a new table and adding custom columns. Here is my method for your reference.

 

Custom table.

Table 2 = CROSSJOIN(VALUES('Table'[Period]),VALUES('Table'[Partner]))

Custom column.

Amount = CALCULATE(SUM('Table'[Amount]),FILTER('Table','Table'[Partner]=EARLIER('Table 2'[Partner])&&'Table'[Period]<=EARLIER('Table 2'[Period])&&'Table'[Category]="Payment"))

vmengmlimsft_0-1729074103704.png

 

 

Best regards,

Mengmeng Li

parry2k
Super User
Super User

@16511151454 

As a best practice, add a date dimension in your model and use it for time intelligence calculations. Once the date dimension is added, mark it as a date table on table tools. Check the related videos on my YT channel

 

Add Date Dimension
Importance of Date Dimension
Mark date dimension as a date table - why and how?
Time Intelligence Playlist

 

Having said that in DAX expression use the date column from the newly added date dimension and also to visualize the data, use the quarter column from the date table. It will fill in the missing period data.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Kedar_Pande
Super User
Super User

Update your existing measure:

Cumulative Payment =
VAR CurrentPartner = SELECTEDVALUE('Table'[Partner])
VAR CurrentPeriod = MAX('Table'[Period])
RETURN
CALCULATE(
SUMX(
VALUES('Table'[Period]),
[Payment]
),
FILTER(
ALLSELECTED('Table'),
'Table'[Period] <= CurrentPeriod &&
'Table'[Partner] = CurrentPartner
)
)

You can create a total measure that sums across partners:

Total Cumulative Payment =
SUMX(
VALUES('Table'[Partner]),
[Cumulative Payment]
)

Thanks for looking into it.

Unfortunately it doesn't change the result.

 

16511151454_0-1728065725986.png16511151454_1-1728065754616.png

 

I'm thinking there should be a way to dynamically create [Payment] values of 0 where it does not exist for a given combination of [Partner] and [Period]...

OktayPamuk80
Helper V
Helper V

Hi,

Try this out (using Period as filtering):

Cumulative Payment =
CALCULATE(
sum(financials[ Sales]),
'calendar'[Month] <= SELECTEDVALUE('calendar'[Month])
)

 

Regards,

Oktay

 

If it helps, appreciate for Kudos and mark as solution 🙏🏻!!!

Thanks for the proposal but it does not work. Moreover SUM() cannot work on a measure and I do not have a table named 'calendar', neither can I create one.

On the table view, where you can view data, you csn create a calendar using the calendar(startdate, enddate).

 

The Start and end date would be min and max of your existing date field in the table. Therefore :

 

Calendar = calendar(min(Date), max(Date))

 

Afterwards, you can connect it in the modeling view. 

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.