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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
PBI5851
Helper V
Helper V

How to do a balance and beginning count for each month ?

nHello,

Below is the raw data i have 

 

RawCountkeydateKeyField
311/30/2020New Shoes
312/31/2020New Shoes
-112/31/2020Discontinued
-11/31/2021Discontinued
-12/28/2021Discontinued

 

And i hope to achieve the below. 

 Nov-20Dec-20Jan-21Feb-21Mar-21Apr-21
Beginning035433
New330000
Discontinued011100
Balance354333

 

But with the logic and dax i have, i am achieving only this. 

 Nov-20Dec-20Jan-21Feb-21Mar-21Apr-21
Beginning035400
New330000
Discontinued011100
Balance354300

 

The March and Apr beginning and balance are incorrect as they are zero's.  This is because of the "selected" variable as per below. 

Balance =
var selected = max(SummaryTable[KeyDate])
Return
CALCULATE(sum(SummaryTable[RawCount]), FILTER(all(SummaryTable), SummaryTable[KeyDate] <= selected))


Beginning =
var selected = max(SummaryTable[KeyDate])
Return
CALCULATE(sum(SummaryTable[RawCount]), FILTER(all(SummaryTable), SummaryTable[KeyDate] < selected))

 

If there is a value for every month in the raw table, i get correct results, but if there are none, then i get no results. Please can you advise on how to get the begin and balance numbers for those months that arent't part of the raw table. 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @PBI5851 ,

 

The solution to this situation is to create a calendar table,

Table 2 = ADDCOLUMNS(CALENDAR(DATE(2020,11,1),DATE(2021,4,30)),"Month-Year",FORMAT([Date],"MMM")&"-"&FORMAT([Date],"YY"),"sort",YEAR([Date])*100+MONTH([Date]))

9.png

10.png

Balance = 
var selected = max(SummaryTable[KeyDate])
Return
CALCULATE(sum(SummaryTable[RawCount]), FILTER(all(SummaryTable), SummaryTable[KeyDate] <= MAX('Table 2'[Date])))
Beginning = 
var selected = max(SummaryTable[KeyDate])
Return
CALCULATE(sum(SummaryTable[RawCount]), FILTER(all(SummaryTable), SummaryTable[KeyDate] < MAX('Table 2'[Date])))

 11.png

 

 

 

Best Regards,

Stephen Tao

 

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
Anonymous
Not applicable

Hi @PBI5851 ,

 

The solution to this situation is to create a calendar table,

Table 2 = ADDCOLUMNS(CALENDAR(DATE(2020,11,1),DATE(2021,4,30)),"Month-Year",FORMAT([Date],"MMM")&"-"&FORMAT([Date],"YY"),"sort",YEAR([Date])*100+MONTH([Date]))

9.png

10.png

Balance = 
var selected = max(SummaryTable[KeyDate])
Return
CALCULATE(sum(SummaryTable[RawCount]), FILTER(all(SummaryTable), SummaryTable[KeyDate] <= MAX('Table 2'[Date])))
Beginning = 
var selected = max(SummaryTable[KeyDate])
Return
CALCULATE(sum(SummaryTable[RawCount]), FILTER(all(SummaryTable), SummaryTable[KeyDate] < MAX('Table 2'[Date])))

 11.png

 

 

 

Best Regards,

Stephen Tao

 

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

@PBI5851 , Try with help from a date table

 

Balance =
CALCULATE(sum(SummaryTable[RawCount]), FILTER(all(Date), Date[Date] <= max(Date[Date])))


Beginning =
CALCULATE(sum(SummaryTable[RawCount]), FILTER(all(Date), Date[Date] < Min(Date[Date])))

 

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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