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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
gtamir
Post Patron
Post Patron

Help with a measure

Hi, The following is a measure from Marco Ruso. It works perfectly, but I want to understand it deeper. Thanks in advance.

1- In the Variable "FirstPurchaseCustomers" is the ADDCOLUMNS a virtual column? If yes, to which table? Sales?

 
New Customers =
VAR FirstPurchaseCustomers =
ADDCOLUMNS (
ALL ( Sales[CustomerKey] ),
"DateOfFirstBuy", CALCULATE ( MIN ( Sales[Order Date] ), ALLEXCEPT ( Sales, Sales[CustomerKey] ) )
)
VAR NewCustomers =
FILTER (
FirstPurchaseCustomers,
CONTAINS ( VALUES ( 'Date'[Date] ), 'Date'[Date], [DateOfFirstBuy] )
)
RETURN
COUNTROWS ( NewCustomers )

 

1 ACCEPTED SOLUTION


@gtamir wrote:

So it stays in memory as long as the project is on and you can refer to it, as I understand.

 


No, the "table" only exists in memory for a few milliseconds while the measure is being evaluated in the context of a query. You cannot refer to it outside of the measure.  "virtual tables" is not a specific term, I'm using "virtual" as an adjective to describe the fact that the table variable is temporary and not persisted anywhere. It only exists for the duration of the evaluation of the measure (this is the way all variables defined using the VAR keyword behave).

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

FirstPurchaseCustomers is table  based on sales, addcolumns create a table

https://docs.microsoft.com/en-us/dax/addcolumns-function-dax

 

The filter will again return the filtered table as

https://docs.microsoft.com/en-us/dax/filter-function-dax

 

and after filter, you are only getting new customers. So countrows of the table is returned.

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p...
https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

So it is a virtual table. 


@gtamir wrote:

So it is a virtual table. 


Yes, it logically creates a virtual 2 column table with the CustomerKey and DateOfFirstBuy columns

@d_gosbell Thank you. So it stays in memory as long as the project is on and you can refer to it, as I understand.

I didn't find any article about virtual tables. Do you know of anything written about the issue?


@gtamir wrote:

So it stays in memory as long as the project is on and you can refer to it, as I understand.

 


No, the "table" only exists in memory for a few milliseconds while the measure is being evaluated in the context of a query. You cannot refer to it outside of the measure.  "virtual tables" is not a specific term, I'm using "virtual" as an adjective to describe the fact that the table variable is temporary and not persisted anywhere. It only exists for the duration of the evaluation of the measure (this is the way all variables defined using the VAR keyword behave).

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.