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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
DataVitalizer
Solution Sage
Solution Sage

DAX: Return the previous nonblankvalue

Hi Community,

I am working on a sales table (1), when the sales value is null I have to return the previous nonblankvalue for each product (2).

I used the following formula but it's not returning the values I am looking for:

DAX_Column = IF(SUM('Table'[Sales])=BLANK();CALCULATE(SUM('Table'[Sales]);PREVIOUSDAY('Table'[DateKey]));SUM('Table'[Sales]))

previous nonblankvalue.png

Could you please help me correcting my formula to get the green column.

Thank you in advance.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

[Column] =
var __product = Products[Product]
var __date = __Products[DateKey]
var __lookupTable =
	filter(
		filter(
			Products,
			Products[Product] = __product
		),
		NOT ISBLANK( Products[Sales] )
		&& Products[DateKey] <= __date 
	)
var __sales =
	MAXX(
		TOPN(
			1,
			__lookupTable,
			Products[DateKey]
		),
		Products[Sales]
	)
return
	__sales

Best

Darek

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

[Column] =
var __product = Products[Product]
var __date = __Products[DateKey]
var __lookupTable =
	filter(
		filter(
			Products,
			Products[Product] = __product
		),
		NOT ISBLANK( Products[Sales] )
		&& Products[DateKey] <= __date 
	)
var __sales =
	MAXX(
		TOPN(
			1,
			__lookupTable,
			Products[DateKey]
		),
		Products[Sales]
	)
return
	__sales

Best

Darek

Hi @Anonymous ,

Thank you for the solution. It works 🙂 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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