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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
curtis5611
Regular Visitor

Calculated column has empty result for some records

I have added a Calculated Column in a Customers Table with this DAX formula:

= VAR CustomerPurchase = FILTER('Sales', 'Sales'[CustomerNo] = CurrentCustomerID)

   VAR SortedPurchase = ADDCOLUMNS(CustomerPurchase, "PurchaseRank", RANKX(CustomerPurchase,         'Sales'[PurchaseDate], , DESC) )

   VAR SecondLastPurchaseRank = MAXX(FILTER(SortedPurchase, [PurchaseRank] = 2), [PurchaseRank])

   RETURN

        MINX(FILTER(SortedPurchase, [PurchaseRank] = SecondLastPurchaseRank), 'Sales'[PurchaseDate])

 

After executing this, most of the records in this Customers Table has results for this Calculated Column, but there are few records having empty cell. I have confirmed that there are Purchase data for these customers. How can I resolve this>

3 REPLIES 3
johnt75
Super User
Super User

Try

Second last purchase date =
VAR AllPurchases =
    CALCULATETABLE ( VALUES ( Sales[PurchaseDate] ) )
VAR MostRecentPurchases =
    TOPN ( 2, AllPurchases, Sales[PurchaseDate], DESC )
VAR Result =
    MINX ( MostRecentPurchases, Sales[PurchaseDate] )
RETURN
    Result

This assumes that you have a relationship from Customer to Sales.

Hi @johnt75 ,

Thanks for your reply. When I tried using your approach, I received this error: 

curtis5611_0-1692950075200.png

The relationship between the Customer and Sales Tables is through the "CustomerNo" field in both tables.

I've never come across that error before, but it sounds like a data quality issue. I would have a look at the customer no field in both tables and make sure that they match up correctly.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors