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
DanielLinda
Helper IV
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)

 

ItemDate  Qty
A2019-05-01  30
A2019-08-01  5
A2019-10-01  15
B2003-12-01  10
B2004-01-01  50
B2004-03-01  20
B2004-04-01  30
C2020-11-01  5
C2021-01-01  15
C2021-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. 

ItemDate  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)

 

Please kindly help me.

 

Thanks in advance.

 

1 ACCEPTED SOLUTION

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, 

721..PNG

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))

 720.PNG

 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.

 

View solution in original post

4 REPLIES 4
VijayP
Super User
Super User

You can donwload this file from link - DOWNLOAD

 

2020-05-22_232539.png




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


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...)

image.png

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, 

721..PNG

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))

 720.PNG

 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.

 

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!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.