cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Helper IV

## Get Previous Running Total for Missing Month

Hi All,

Let say I have two tables like below, I want to make accumulative line graph of which line should always increase.

The 'Date' table and 'ShipQty' table has relation in date column.

X axis: Date, Y axis: Qty

'Date'

 Date 2001-01-01 2001-01-02 2001-01-03 ~ 2022-12-30 2022-12-31

'ShipQty' - (Qty is MTD value)

 Item Date Qty A 2019-05-01 30 A 2019-08-01 5 A 2019-10-01 15 B 2003-12-01 10 B 2004-01-01 50 B 2004-03-01 20 B 2004-04-01 30 C 2020-11-01 5 C 2021-01-01 15 C 2021-02-01 10

How can I get previous running total for missing month of each item?

The result should be like below.

'Running Total' - (Should not have missing month.)

The records in red should be inserted with previous qty and missing month.

The Qty values in blue should be the result of sum of previous value and current month.

 Item Date Qty A 2019-05-01 30 A 2019-06-01 30(Previous value) A 2019-07-01 30(Previous value) A 2019-08-01 35(30+5) A 2019-09-01 35(Previous value) A 2019-10-01 50(35+15) B 2003-12-01 10 B 2004-01-01 60(10+50) B 2004-02-01 60(Previous value) B 2004-03-01 80(20+60) B 2004-04-01 110(30+80) C 2020-11-01 5 C 2020-12-01 5(Previous value) C 2021-01-01 20(15+5) C 2021-02-01 30(10+20)

1 ACCEPTED SOLUTION
Community Support

Hi @DanielLinda ,

You could create a calendat table (2019/1/~2022/12/21)

``calendar = CALENDAR(date(2019,1,1), date(2022,12,31))``

then create relationship between calendar and fact table, and use measure and calendar in table like below,

``Measure = var  maxd=CALCULATE(MAX('Table'[Date]), ALLEXCEPT('Table','Table'[Item]))  return CALCULATE(SUM('Table'[  Qty]), FILTER(ALLSELECTED('calendar'), 'calendar'[Date]<=MIN('calendar'[Date]) && MIN('calendar'[Date])<=maxd))``

It will show all months in each year, and end with the max month in fact table. You could refer to my sample for details.

Best Regards,
Zoe Zhi

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

4 REPLIES 4
Super User

MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!

Helper IV

Thanks @VijayP

I checked your file but one thing that I wonder is how could you make every month in "table".

Because in my case, there is no row for missing value, even month value.

The hard thing is insert missing month row if it is missed.

For example my table looks below, I should create April.

(Sorry for Date language...)

Community Support

Hi @DanielLinda ,

You could create a calendat table (2019/1/~2022/12/21)

``calendar = CALENDAR(date(2019,1,1), date(2022,12,31))``

then create relationship between calendar and fact table, and use measure and calendar in table like below,

``Measure = var  maxd=CALCULATE(MAX('Table'[Date]), ALLEXCEPT('Table','Table'[Item]))  return CALCULATE(SUM('Table'[  Qty]), FILTER(ALLSELECTED('calendar'), 'calendar'[Date]<=MIN('calendar'[Date]) && MIN('calendar'[Date])<=maxd))``

It will show all months in each year, and end with the max month in fact table. You could refer to my sample for details.

Best Regards,
Zoe Zhi

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

Microsoft Employee

Your Date table should have all the dates (and months) from the min to max date of your other table.  Are you making your visuals with the Date (or month) from your Date table?  If you have a measure that calculate YTD, you should get a value for each Date or Month.  Have you made a table (or chart) with the Date or Month column from the Date table, and a measure like TOTALYTD(Sum(Table[Sales]), 'Date'[Date])?

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat

Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.