cancel
Showing results for
Did you mean:

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Frequent Visitor

## Calculate[calling-measure] vs Calculate(writing-measure)

Hello everyone, I'd be very greatful if someone could help me out!

I am trying to compute new customers [newcustomercount] and have used the dax code used here for this:
https://www.sqlbi.com/articles/computing-new-customers-in-dax/

I have also created a copy of my 'Date' table called 'PreviousDate'  to be able to select a single month in a visual and get 6 months filter the previous 6 months of the date table. Code for this has come from here:

Here is a link to my pbix file in case you'd like to check it out! Thanks if you do!

The Problem

I have noticed that I get a different result when,

calling a measure within calculate:

[prev6mths|callingmeasure]

.........
VAR Result =
CALCULATE(
[newcustomercount],
REMOVEFILTERS ('Date'),............

vs.

writing the measure within calculate:
[prev6mths|writtingmeasure]
................

VAR Result =

CALCULATE(

COUNTROWS (

FILTER (

CALCULATETABLE (

...............

Results:

Relationships:

My Measures:

newcustomercount =
COUNTROWS (
FILTER (
CALCULATETABLE (
VALUES ( NewRevenue[Account_Id] ),
"DateOfFirstBuy", CALCULATE ( MIN ( NewRevenue[Report_Month] ) )
),
ALL ( 'Date' )
),
CONTAINS ( VALUES ( 'Date'[Date] ), 'Date'[Date], [DateOfFirstBuy] )
)
)

prev6mths|callingmeasure =
VAR NumOfMonths = -6
VAR ReferenceDate =
MAX ( 'Date'[Date] )
VAR PreviousDates =
DATESINPERIOD ( 'PreviousDate'[Date], ReferenceDate, NumOfMonths, MONTH )
VAR Result =
CALCULATE (
[newcustomercount],
REMOVEFILTERS ( 'Date' ),
KEEPFILTERS ( PreviousDates ),
USERELATIONSHIP ( 'Date'[Date], 'PreviousDate'[Date] )
)
RETURN
Result

prev6mths|writtingmeasure =
VAR NumOfMonths = -6
VAR ReferenceDate =
MAX ( 'Date'[Date] )
VAR PreviousDates =
DATESINPERIOD ( 'PreviousDate'[Date], ReferenceDate, NumOfMonths, MONTH )
VAR Result =
CALCULATE (
COUNTROWS (
FILTER (
CALCULATETABLE (
VALUES ( NewRevenue[Account_Id] ),
"DateOfFirstBuy", CALCULATE ( MIN ( NewRevenue[Report_Month] ) )
),
ALL ( 'Date' )
),
CONTAINS ( VALUES ( 'Date'[Date] ), 'Date'[Date], [DateOfFirstBuy] )
)
),
REMOVEFILTERS ( 'Date' ),
KEEPFILTERS ( PreviousDates ),
USERELATIONSHIP ( 'Date'[Date], 'PreviousDate'[Date] )
)
RETURN
Result

Thanks for reading, I would be very greatful if anyone could help me out!

0 REPLIES 0

Announcements

#### Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

#### Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

#### The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors