cancel
Showing results for 
Search instead for 
Did you mean: 

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

Reply
Lhans
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:
https://www.youtube.com/watch?v=d8Rm7dwM6gc&t=601s

Here is a link to my pbix file in case you'd like to check it out! Thanks if you do!
https://drive.google.com/drive/folders/1j93uX4dUL6JoTJxDt3LMPWdHQD0_Nssj?usp=sharing

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 (

                ADDCOLUMNS (

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


Results:

Lhans_0-1691950111070.png

 

Relationships:

Lhans_1-1691950174820.png

 


My Measures:

newcustomercount =
COUNTROWS (
    FILTER (
        CALCULATETABLE (
            ADDCOLUMNS (
                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 (
                    ADDCOLUMNS (
                        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

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

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

Power BI Fabric Summit Carousel

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