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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
GMC
New Member

How to have a running balance of distinct counts based on different column dates

Hi, I have a transaction table that has a start date and completion date columns. I need to determine the count of OPEN transactions per month. A transaction is considered open for a reference month if its start date is on or before that month, AND ( Completion date is either blank, OR its month is after the reference month). I have to have it in such a way, so when I plot its graph, report filters using the transaction table columns are still applicable.   

  

For example: the first table shows the data set, and the second table shows the expected Open ItemRunning Balance.

The challenge I have is to come up with the correct measure so that it is report filterable on the fly. 

Thank you in advance.

GMC_0-1595959504547.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

 

// For this you need a DateTable that's DISconnected from Documents.
// You want this measure to work correcly not only for months
// but for any period of time, even 1 day. Generally, you should
// always aim at creating measures that make sense for ANY
// selection in dimensions. I'd also suggest that you not use
// BLANKs for Completion Date. Instead, use something like
// DATE(3000, 3, 1). This will make the code sipler and potentially
// faster as you won't need to check for BLANK dates. Of course,
// the Start Date and Completion Date columns should be hidden.

[# Open Docs] =
var __lastVisibleDate = MAX( DateTable[Date] )
var __result =
	CALCULATE(
		COUNTROWS( Documents ),
		// assuming that Start Date will never be BLANK...
		Documents[Start Date] <= __lastVisibleDate,
		OR(
			Documents[Completion Date] > __lastVisibleDate,
			// If you remove BLANKS as suggested, you can
			// remove OR and leave only the first condition
			// under OR.
			ISBLANK( Documents[Completion Date] )
		)
	)
RETURN
	__result

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

 

// For this you need a DateTable that's DISconnected from Documents.
// You want this measure to work correcly not only for months
// but for any period of time, even 1 day. Generally, you should
// always aim at creating measures that make sense for ANY
// selection in dimensions. I'd also suggest that you not use
// BLANKs for Completion Date. Instead, use something like
// DATE(3000, 3, 1). This will make the code sipler and potentially
// faster as you won't need to check for BLANK dates. Of course,
// the Start Date and Completion Date columns should be hidden.

[# Open Docs] =
var __lastVisibleDate = MAX( DateTable[Date] )
var __result =
	CALCULATE(
		COUNTROWS( Documents ),
		// assuming that Start Date will never be BLANK...
		Documents[Start Date] <= __lastVisibleDate,
		OR(
			Documents[Completion Date] > __lastVisibleDate,
			// If you remove BLANKS as suggested, you can
			// remove OR and leave only the first condition
			// under OR.
			ISBLANK( Documents[Completion Date] )
		)
	)
RETURN
	__result

 

Thanks Daxer! I have accepted it as the solution.

lbendlin
Super User
Super User

use a CROSSFILTER(...,NONE)  to fill in the date gaps.  That will then allow your measure to mark each transactions status by date.

Hi Ibendlin, please elaborate on the application of crossfilter. Thank you 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.