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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
RobertSlattery
Resolver III
Resolver III

Calculate Opening Balance of Selected Range

 

Open Orders Month Opening 2 = CALCULATE(
	[Open Orders],
	FILTER(ALL('Dim Date'),
		'Dim Date'[Date] < DATE(2017,12,1)
	)
)

I have, for example, December and Jan selected in my visual (using a page filter) and I want to use the first visible date in a calculation.  In other words, I want to replace the above with

Open Orders Month Opening 2 = CALCULATE(
	[Open Orders],
	FILTER(ALL('Dim Date'),
		'Dim Date'[Date] < [firstDateVisible]
) )

I tried 

firstDateVisible = CALCULATE(
	FIRSTDATE('Dim Date'[Date]),
	ALLSELECTED('Dim Date'[Date])
)

and although it works in a Card, it causes the Order Opening measure to return blank.

How can I get the first selected date inside the measure?

 

1 ACCEPTED SOLUTION

Hi @RobertSlattery,

When you select data range in slicer, the 'Orders' also be filtered during 2017/12/1-2018/1/31, the table visual still affected by the filter context. So Order Opening measure to return blank. Please write the measure using Variable as follows.

Open Orders Month Opening_test = VAR first_date=[firstDateVisible]
RETURN CALCULATE(
	SUM(Orders[Open Orders]),
	FILTER(ALL('Dim Date'),
		'Dim Date'[DateRaw] < first_date
	),
    ALL(Orders)
)


You will get expected result.

expected resultexpected result
Please download attachment file for more details.

Best Regards,
Angelia

View solution in original post

4 REPLIES 4
v-huizhn-msft
Microsoft Employee
Microsoft Employee

Hi @RobertSlattery,

>>although it works in a Card, it causes the Order Opening measure to return blank.

It's confusing. You mean in a Card visual, Order Opening measure returns the correct result, while it returns uncorrectly in other visualization? Do you mind share you sample table/.pbix file for further analysis? Do hide your sensitive information before unloading it, or you can send it by private information.

Thanks,
Angelia

Thanks @v-huizhn-msft, I uploaded an example here

Hi @RobertSlattery,

When you select data range in slicer, the 'Orders' also be filtered during 2017/12/1-2018/1/31, the table visual still affected by the filter context. So Order Opening measure to return blank. Please write the measure using Variable as follows.

Open Orders Month Opening_test = VAR first_date=[firstDateVisible]
RETURN CALCULATE(
	SUM(Orders[Open Orders]),
	FILTER(ALL('Dim Date'),
		'Dim Date'[DateRaw] < first_date
	),
    ALL(Orders)
)


You will get expected result.

expected resultexpected result
Please download attachment file for more details.

Best Regards,
Angelia

The graph does not respond to the slicer and your Open Orders Month Opening_test measure breaks if you select a date hierarchy for the graph axis. Smiley Sad

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.