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
m_aa
Advocate I
Advocate I

Count the number of repeated orders

Hi all,

 

I'm relatively new to Power BI and have some issues with DAX, hope I'll find help here.

 

What I aim to do is to show the total number of orders in chosen period and how much of them are from returning customers. Both are shown in card visuals. I have no problems with total quantity, however repeated orders...

 

Here's an example of my data. Basically all fields I need are UserID, Order Number, and Date of Purchase

m_aa_0-1643020446150.png

The result I expect to get is two cards, one of them shows value 25 (the total amount of orders) and 22 (number of repeated orders).

What I managed to do is to define order index number by customer with RANKX function:

rank measure = RANKX(FILTER(ALLSELECTED('OrderTable'),'OrderTable'[USER_ID]=SELECTEDVALUE('OrderTable'[USER_ID])),CALCULATE(SELECTEDVALUE('OrderTable'[ACCOUNT_NUMBER])),,ASC,Dense)

Which leads to this:

m_aa_1-1643021015896.png

The reason I use Account Number as a value instead of date is because there might be few orders in one day which would affect the rank number. I also need a rank to be a measure, not a column, because it should be sensitive to date filter which now works perfectly.

 

However, I can't use this measure in card filter (don't know why exactly, it's just unavailable when I put the measure in filter field). I tried to make flag measure, something like

flag = IF('rank measure'>1,1,0)

(also tried text values instead of 0 and 1) and use it in filter, but it didn't work either. 

 

Does anyone know why are these measure are not applicable in filters? Is there a way to make it work? Or do I need completely different approach to this case?

 

Any help is much appreciated!

 

Kind regards,

Nastia

 

1 ACCEPTED SOLUTION
v-cgao-msft
Community Support
Community Support

Hi @m_aa ,

 

I created a simple.

vcgaomsft_0-1643175221665.png

vcgaomsft_1-1643175244195.png

Then try these measures.

 

 

 

total number of orders = COUNTROWS('Table')
returning customers = [total number of orders] - COUNTROWS(DISTINCT('Table'[USER_ID]))

 

 

 

The result should be like this and slicer also works fine.

vcgaomsft_2-1643175427734.png

vcgaomsft_3-1643175463829.png

Also, attached the pbix file as the reference.

 

Best Regards,

Community Support Team_Gao

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

 

 

 

View solution in original post

2 REPLIES 2
v-cgao-msft
Community Support
Community Support

Hi @m_aa ,

 

I created a simple.

vcgaomsft_0-1643175221665.png

vcgaomsft_1-1643175244195.png

Then try these measures.

 

 

 

total number of orders = COUNTROWS('Table')
returning customers = [total number of orders] - COUNTROWS(DISTINCT('Table'[USER_ID]))

 

 

 

The result should be like this and slicer also works fine.

vcgaomsft_2-1643175427734.png

vcgaomsft_3-1643175463829.png

Also, attached the pbix file as the reference.

 

Best Regards,

Community Support Team_Gao

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

 

 

 

Hi @v-cgao-msft ,

 

this works perfectly, thank you a lot!

The only thing I forgot to mention is that in my data there might be few rows per order (if there were different products in order), so I just added SUMMARIZE function to total orders measure.

 

Thanks for your help agian!

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.