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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Kudoed Authors