Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

Problem DAX measure

Hi all, I am a beginer in Power BI, i have strugggling with a mearsure problem. For example,

Table 1 

Customer_IDdateRegisterReferral LinkFirst VisitFirst Click into bagFirst_PurchaseOnline shop Channel


I want to calculate the first_Purchase(FP) for the Customer_ID by ignoring the online shop channel (obviously customer ID 26 his first_purhcase(FP) would be 1/4/2011 by ignoring the shop Channel

I only got the right answer once i created a new table by the following

step 1.

New Table = CALCULATETABLE(SUMMARIZE(table 1,table 1[Customer_ID], "Mdate",CALCULATE(MIN(Table 1[date]),Table 1[First_Purchase]=1)), Table 1[First_Purchase]=1)

step 2.

Nr of customer with at least 1 first purchase = count('New table'[Mdate])

The answer will be 1 (as i only want to get the min date of first purchase)


However, i used same logic to create the measure in table

e.g distinctcount(table 1[customer ID],first_purchase =1). or countrow(summarize(tabl 1..))


the result i get is larger than the New Table answer. it seem this in table 1 counting those record with different shop channels therefore this customer ID would be show again on Dec 2013 (What i want is just show once in april 2011).

I don't want to change the table structure it is because i have to do further analysis in all customer's first visit and click into bag etc..


Thanks and appreciate with your help

Super User IV
Super User IV

Re: Problem DAX measure

Hi @Yikwun831, I am not sure that I follow all of this 100% but if you want a visual where you have the Customer_ID and min date of first purchase you should be able to create a measure like this:


Measure = 
VAR __customerID = MAX('Table 1'[Customer_ID])
VAR __table = FILTER(ALL('Table 1'),[Customer_ID] = __cucstomerID && [First_Purchase] = 1
VAR __date = MINX(__table,[date])

Put that measure into a visual with your Customer_ID and see if that is what you are looking to achieve.


Not the Power BI thought police...

I have NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!
Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

Frequent Visitor

Re: Problem DAX measure

Thanks a lot Deckler, 


In this " __cucstomerID && [First_Purchase] = 1"

i don't have the selection of [first_purchase] (this column data i generated by query from database), so at the memont I still cannot test the measure yet.


In addition, I have loads of data for example customer ID 27,28 etc. Their each first action (first view, first purchase...) has been fully recorded and generated a row for each first action in different online shop channels.


So ultimately, i would like to show their first purchase by year month. 
for example, Customer ID 26 only show in april 2011

but not in both april 2011 and Dec 2013 (otherwise it will be duplicate my calculation for new customer because i am defining the totally new customer instead of a exist customer who having a new purchase in new channel but they have already purchase in another channels


Thank you so much Deckler!

Community Support
Community Support

Re: Problem DAX measure

Hi @Yikwun831 ,


Here is my sample data.


Then I created a new measure to get date of first purchase.

Measure =
    MIN ( test[date] ),
    ALLEXCEPT ( test, test[ID] ),
    test[first purchase] = 1

Here is the result. Does this suit your needs?



Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
Frequent Visitor

Re: Problem DAX measure

Yes, this measure is great! however, I want to count their first purchase instead of showing



For this example, i want is ID_26 will be only showed in April 2011, 27 only in May 2013 and 28 only May 2015.

It only happens in the month that has its inital first purchase (even they have another first purchase in other channel)


secondly, i want to visualize that measure no matter in matrix form / stacked chart.

I tried many ways and method, but finally it doesn't work.
the graph will show all the first purchase in different channles.


thanks a lot mate! it would be great if i have your help

Community Support
Community Support

Re: Problem DAX measure

Hi @Yikwun831 ,


I am still a little ambiguous about your needs. Would you like to provide a sample result you want?
And you can download my test file, I created two kinds of matrix form in it.


Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
Frequent Visitor

Re: Problem DAX measure

Thanks for your help. I am really appreciate that.


I have downloaded your sample and read through it, it was really good! it helps me to understand the DAX and logic behind this.

The matrix with measure 1 is the thing i want exactly (but the number of total of row&column seems all 0)


Furthermore, i would like to have the stacked column chart with x axis = year month (Date) and y-axis = sum of the no. of first purchase in that month (the "first purchase" has been defined in previously)

then using the same dax to create the new column like your table column 1 and 2, but it doesn't work in my tabke.


Hence,I am just wondering that might due to the edit queries problem? ( as I extract the data from database by SQL and then consolidate the data)

Basically, my first step is extracting data (the first view, first purchase etc all is timely data) by SQL, then i unpivoted columns and used conditional cloumn to create new columns for first purchase, etc.

Customer IDOnline shop ChannelRegfirst viewfirst clickfirst purchase
262 14/5/2010  
269   5/6/2011
268   18/12/2014
2613  18/12/2010 
273   9/9/2013
274  1/8/2013 
286 14/4/2018  


then i unpivoted columns

Customer IDOnline shop ChannelTypeDate
262first view14/5/2010
269first purchase5/6/2011
268first purchase18/12/2014
2613first click18/12/2010
273first purchase9/9/2013
274first click1/8/2013
286first view14/4/2018

then conditional column

Customer IDDateOnline shop ChannelRegfirst viewfirst clickfirst purchase


after all, i started working with those data like creating the measure and visualize the date

is there any mistake happen so i cannot create the measure and column like yours? 



Helpful resources

New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors