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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
jbx999
Regular Visitor

Gap filling all months for each category

I have a Stock table which represents changes to stock levels for each product every month.

It looks something like this:

 

Product_ID  Description  Year-Month  Quantity_Change  Quantity_RT (Measure Column)  
1Product 12018-01100100
1Product 12018-02120220
2Product 22018-015050
2Product 22018-05-2030
1Product 12018-06-15070
2Product 22020-10-1020
1Product 12020-1240110

 

Note that the last column was added as a running total in DAX. 

 

I want to plot the stock levels every month for each product. If I try to plot this table (Year-Month on the x-axis and Quantity_RT on the y-axis) I get a lot of gaps and the data will stop at the last month where there was an update. 

 

I have a CalendarTable which has all the Year-Month entries, from the earliest date till `Today()`, which is linked via a relationship already using the Year-Month field.  

 

Is there a way to gap fill all months for each product (using DAX since I need to use the running total column)? For each product and year-month pair, if there is no entry, I want to use the value of the previous month (since it means that for that product there was no change). 

 

If there is no previous value (it is the first time the product appears), I can either leave it out, or set it to 0, it doesn't matter, whatever is easiest. 

 

So the result I want is the following:

 

 

Product_ID  Description  Year-Month  Quantity_Change  Quantity_RT (Measure Column)  
1Product 12018-01100100
1Product 12018-02120220
1Product 12018-030220
1Product 12018-040220
1Product 12018-050220
1Product 12018-06-15070
...    
1Product 12020-11070
1Product 12020-1240110
2Product 22018-015050
2Product 22018-02050
2Product 22018-03050
2Product 22018-04050
2Product 22018-05-2030
...    
2Product 22020-09030
2Product 22020-10-1020

 

All going up to the current month. The rows in italics show the gap filled ones that were added. 

 

I was thinking of trying to do some outer join between the CalendarTable and the Stock table to generate all the month-product pairs, but not sure how to go about this to use the previous value. 

 

Any idea how to go about this?

 

 

 

 

 

1 ACCEPTED SOLUTION

Hi, @jbx999 

I create a sample pbix file for you reference.

You need to add a new column 'YM' in a new Calendar table:

YM = FORMAT('Calendar'[Date],"YYYY-MM")

Then add a new measure as below to calculate the value:

Quantity_RT = CALCULATE(SUM('Table'[Quantity_Change]),FILTER('Table','Table'[Year-Month]<=MAX('Calendar'[Date])))

11.png

 

Best Regards,
Community Support Team _ Eason

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@jbx999 , If you are using running total using date tbale , then and using moth year from date table on axis, you should get the month with missing

 

Cumm Sales = CALCULATE(SUM(Sales[Sales Amount]),filter(allselected('Date'),'Date'[date] <=max('Date'[date])))

 

or

 

 

Cumm Sales = CALCULATE(SUM(Sales[Sales Amount]),filter(all('Date'),'Date'[date] <=max('Date'[date])))

 

use column from date table on axis for month, date qtr, year etc

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

The running total is using the Year-Month, but it has gaps. There are some months where there was no update to the quantity. I want to "gap fill" them so that the running total does not have gaps. 

 

My current Quantity_RT is calculated as follows already:

 

```

Quantity_RT = sumx(filter('Stock',
[Product_ID] =earlier([Product_ID]) && [Year-Month] <= EARLIER([Year-Month])), [Quantity])
```

 

I think I can either fill in the gaps before, with Quantity = 0 for those missing months, or fill them afterwards. But I can't understand how your solution fits. 

 

 

Hi, @jbx999 

I create a sample pbix file for you reference.

You need to add a new column 'YM' in a new Calendar table:

YM = FORMAT('Calendar'[Date],"YYYY-MM")

Then add a new measure as below to calculate the value:

Quantity_RT = CALCULATE(SUM('Table'[Quantity_Change]),FILTER('Table','Table'[Year-Month]<=MAX('Calendar'[Date])))

11.png

 

Best Regards,
Community Support Team _ Eason

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors