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
amikm
Helper V
Helper V

Measure is not calculating properly

I am trying to get a distinct count of customers who have purchased any product in the past 12 months where the SalesAmount is greater than 0.

 

I wrote the below formula to calculate this:-
MeasureR12CustomerCount:=CALCULATE(DISTINCTCOUNT(Account[customernumber]),FILTER(Calendar,Calendar[CalendarDate]>=EDATE([LastClosedMonth],-11) && Calendar[CalendarDate]<=[LastClosedMonth] ),FILTER(Sales,Sales[SalesAmount]>0))

 

When I am trying to validate this data, I can see below customer has negative sales, but still, MeasureR12CustomerCount is showing as 1.

1.png

 

When I tried to see the details for this data, I am able to find below information:
2.png

This means the same customer has made two purchases/refunds of products on the same day out of those two only one Product has positive SalesAmount and hence count is showing 1. But If you see the first screenshot, the count is also showing one there as well for -180 USD dollars ( -207+27)

I want to fix this formula, What I want at aggregate If SalesAmount > 0, I want the count for that customer, If it is negative, then I want to count as 0 for that customer. In my case aggregate is -180 USD dollars. So, I want the customer count as 0.

1 REPLY 1
daxer-almighty
Solution Sage
Solution Sage

 

// You have not shown the exact layout of
// your model (which is crucial to
// write correct DAX), so the DAX below may
// need an adjustment to give you
// what you're after in your model.

MeasureR12CustomerCount :=
var LastDate_ = [LastClosedMonth]
var FirstDate_ = EDATE ( [LastClosedMonth], -11 )
var Result =
    COUNTROWS(
        FILTER(
            DISTINCT( Account[CustomerNumber] ),
            CALCULATE(
                // Measures must never be preceded
                // with the name of the table. Columns,
                // on the other hand, must always be.
                // Calendar must be a proper date table
                // in the model and it should filter
                // the fact table on InvoiceDate. You
                // should never put any fields from a
                // fact table on the canvas. Slicing 
                // must only be done via dimensions.
                // In fact, fact tables should always
                // be hidden from the end user (with the
                // exception of a degenerate dimension).
                [SalesAmount] > 0,
                Calendar[CalendarDate] <= LastDate_,
                FirstDate_ <= Calendar[CalendarDate]
            )
        )
    )
return
    Result

 

Helpful resources

Announcements
November Fabric Update Carousel

Fabric Monthly Update - November 2025

Check out the November 2025 Fabric update to learn about new features.

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!

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.

Users online (25)