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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
jarwest
Helper II
Helper II

Running Sum Bar Chart Help

Hey all,

 

I'm working on making a bar graph that will display the running sum of items bought and sold each quarter.

I don't have a good example of sample data, but I have 3 columns I think I can perform this task with.

item - string, name/description of the item

id - string, unique identifier. is not null

bought - datetime, displays the date the item was purchased. is not null

sold - datetime, displays the date the item was sold. If null, item was never sold/needs to be sold.

 

so a tiny example of this data would be

ItemIDboughtsold
4x6 bolt11/2/223/12/23
8x12 bolt21/23/232/23/23
3" washer32/10/23 
2" bradford nail44/1/234/5/23
2x4 pressed board57/2/23 

The number of rows would determine the quantity of items. For example, if 3 rows have a bought value of 3/14/23, that means 3 items were bought on 3/14/23.

 

My end goal is creating a bar chart displaying the running sum of sold items over the course of each quarter/year.

I believe I can easily make this visualziation if I can conver the data above into a format like this below

YearQuarterBoughtActualBoughtRunningSoldActualSoldRunning
202313322
202321413
202331503

 

I need to find a statement to create a calculated table that takes in data from table 1 and makes it match table 2.

I believe I'd be using SUMMARIZE() for this, but I'm not sure how to populate out this formula properly, and im having significant trouble finding resources online for this situation.

The nearest I've gotten was
newTable = summarize(oldTable, "year", YEAR(bought), "quarter", QUARTER(bought), ...)

I've been struggling for the past 6 hours to find what to put in for the remaining columns to get the calculations I want.

 

Any and all help would be greatly appreciated.

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @jarwest 

 

You can try the following methods.

Date table:

vzhangti_0-1695106941952.png

Measure:

BoughtActual = 
Var _minQdate=CALCULATE(MIN('Date'[Date]),ALLEXCEPT('Date','Date'[Quarter]))
Var _maxQdate=CALCULATE(MAX('Date'[Date]),ALLEXCEPT('Date','Date'[Quarter]))
Return
CALCULATE(COUNT('Table'[ID]),FILTER(ALL('Table'),[bought]>=_minQdate&&[bought]<=_maxQdate))+0
SoldActual = 
Var _minQdate=CALCULATE(MIN('Date'[Date]),ALLEXCEPT('Date','Date'[Quarter]))
Var _maxQdate=CALCULATE(MAX('Date'[Date]),ALLEXCEPT('Date','Date'[Quarter]))
Return
CALCULATE(COUNT('Table'[ID]),FILTER(ALL('Table'),[sold]>=_minQdate&&[sold]<=_maxQdate))+0

vzhangti_1-1695106991090.png

New table:

New table = SUMMARIZE('Date','Date'[Year],'Date'[Quarter],"BoughtActual",[BoughtActual],"SoldActual",[SoldActual])

Column:

BoughtRunning = SUMX(FILTER('New table',[Quarter]<=EARLIER('New table'[Quarter])),[BoughtActual])
SoldRunning = SUMX(FILTER('New table',[Quarter]<=EARLIER('New table'[Quarter])),[SoldActual])

vzhangti_2-1695107054342.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

2 REPLIES 2
v-zhangti
Community Support
Community Support

Hi, @jarwest 

 

You can try the following methods.

Date table:

vzhangti_0-1695106941952.png

Measure:

BoughtActual = 
Var _minQdate=CALCULATE(MIN('Date'[Date]),ALLEXCEPT('Date','Date'[Quarter]))
Var _maxQdate=CALCULATE(MAX('Date'[Date]),ALLEXCEPT('Date','Date'[Quarter]))
Return
CALCULATE(COUNT('Table'[ID]),FILTER(ALL('Table'),[bought]>=_minQdate&&[bought]<=_maxQdate))+0
SoldActual = 
Var _minQdate=CALCULATE(MIN('Date'[Date]),ALLEXCEPT('Date','Date'[Quarter]))
Var _maxQdate=CALCULATE(MAX('Date'[Date]),ALLEXCEPT('Date','Date'[Quarter]))
Return
CALCULATE(COUNT('Table'[ID]),FILTER(ALL('Table'),[sold]>=_minQdate&&[sold]<=_maxQdate))+0

vzhangti_1-1695106991090.png

New table:

New table = SUMMARIZE('Date','Date'[Year],'Date'[Quarter],"BoughtActual",[BoughtActual],"SoldActual",[SoldActual])

Column:

BoughtRunning = SUMX(FILTER('New table',[Quarter]<=EARLIER('New table'[Quarter])),[BoughtActual])
SoldRunning = SUMX(FILTER('New table',[Quarter]<=EARLIER('New table'[Quarter])),[SoldActual])

vzhangti_2-1695107054342.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

amitchandak
Super User
Super User

@jarwest , Make sure bought and sold do not have timestamp else create dates without timestamp

 

example new column

bought date = datevalue([bought])

 

Join both of them with a date table having year, qtr, month etc. One join will be inactive, that you can activate using userealtionship

 

Assume bought is active .

measures

m1=  countrows(Table)

 

Using sold date

 

calculate( countrows(Table) ,USERELATIONSHIP ('Table'[sold], 'Date'[Date]))

 

 

refer

HR Analytics - Employees as on Date : https://youtu.be/e6Y-l_JtCq4
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...
Power BI HR Active Employee Tenure Bucketing, and Hired, Terminated, and Active employees: https://youtu.be/fvgcx8QLqZU

 

Date == Addcolumns(calendar(date(2012,01,01), date(2024,12,31) ), "Month no" , month([date])
, "Year", year([date])
, "Month Year", format([date],"mmm-yyyy")
, "Month year sort", year([date])*100 + month([date])
, "Qtr Year", format([date],"yyyy-\QQ")
, "Qtr", quarter([date])
, "Month",FORMAT([Date],"mmmm")
, "Month sort", month([DAte])
, "FY Year", if( Month(([DAte])) <7 , year(([DAte]))-1 ,year(([DAte])))
, "Is Today" ,if([Date]=TODAY(),"Today",[Date]&"")
,"Day of Year" , datediff(date(year([DAte]),1,1), [Date], day)+1
, "Month Type", Switch( True(),
eomonth([Date],0) = eomonth(Today(),-1),"Last Month" ,
eomonth([Date],0)= eomonth(Today(),0),"This Month" ,
Format([Date],"MMM-YYYY") )
,"Year Type" , Switch( True(),
year([Date])= year(Today()),"This Year" ,
year([Date])= year(Today())-1,"Last Year" ,
Format([Date],"YYYY")
)
)

 

 

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

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

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 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.