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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
ahmed9s
Helper I
Helper I

Count number of transactions for users with more than one transaction only

Hello,

 

I am very new to the community and new to PowerBI as well. I have found the solutions here very useful. I stuck with a calculation that i can easily do in Excel but having difficulty understanding the right approach in DAX.

 

I have one table with a column 'userID' and another column 'order total' for each transaction; this table also has a 'date & time' column. I needed to return a total number of transactions for only those users who have more than one transation.

 

As such that for following data:

 

User   | order total

User1 | 12

User1 | 12

User2 | 10

User3 | 1

User3 | 1

User3 | 1

User4 | 1

User5 | 2

 

The result should be '5' as user1 and user3 have more than one transaction each and a total of 5. Ignoring all who have only 1 transactions.

 

Would would be right approach to achieve this and can someone help with the dax formula.

 

Thanks,

Ahmed 

16 REPLIES 16
parry2k
Super User
Super User

@ahmed9s there are few ways to do this

 

try this measure

 

Measure 3 = 
CALCULATE ( 
    COUNTROWS ( 'Table' ), 
    FILTER (
        SUMMARIZE ( 'Table', 'Table'[User], "__cnt", COUNTROWS ( 'Table' ) ),
        [__cnt] > 1
    )
) 

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k . Sorry, first part of my previous message got deleted.
Thank you for your solution. I had came to a similar solution as follows:

CALCULATE(SUM(orders[Count Transactions]),
FILTER(
SUMMARIZE(orders,orders[userID],
"Total Purchases", [Count Users]),
[Total Purchases]>=2))

@ahmed9s so I'm confused, it is working or not working?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k No. It is not working. the total is correct. But when i combine it with date, or users in the table there are big missing numbers as shown in the pic i attached.

@parry2k Is there another approach to solve this?

Screen.png

Grand total is correct. But the underlying groups does not add up to the total.

 

Icey
Community Support
Community Support

Hi @ahmed9s ,

 

 

Grand total is correct. But the underlying groups does not add up to the total.

 


What does it mean? What should the result you want be?

 

Please share us with more details. It is best to create some sample data with the same structure as your real data.

 

 

 

Best Regards,

Icey

@ahmed9s solution attached, look at page 4 in attached and a table called Hour Group ignore everything else in the file.

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k Thank you very much!

@parry2k Thanks again for the help. Implementing the solution on my model has clarified certain concepts for me.

 

I am having issue when i filter the visual with a slicer for a specific month. Without the filter for a specific month it works perfect. but when i select a month the totals go quite a bit off. Is there is a solution for this? 

@ahmed9s you have to be more clear what is off, provide numbers otherwise it is not clear, I requested you to change the measure but not sure if you had a chance to do it or not, here is revised pbix file.

 

Read this post to get your answer quickly.

https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k Thank you for the link.

 

Ok, i played with the sample data. I want to be able to count only the users with multiple orders within a given month. What your suggested measures are doing is counting users who have multiple orders in the whole data set. I have updated the sample data and created 'desired results' summary along with a summary showing 'current results' which are given if we use the following measure for 'Orders Count by Users':

Orders Count by Users = CALCULATE ( [Total Orders], ALLEXCEPT ( orders, orders[userID] ) )

 

This is the sample data: https://drive.google.com/file/d/1VwKGuZ4xeOTf30hWvOOuYfWKg9ObN5Al/view?usp=sharing

 

I am sorry for not being able to describe my desired results in the beginning. I am gaining clearer understanding of the underlying issue.

Hello everyone and @parry2k. I am still curious to undertsand what could be one approach to achieve the desired results.

@Icey, Thank you for the suggestion. I worked a bit with a sample data and that highlighted for me the issue.

 

After getting the count of transactions of users having only multiple transactions, i need to group/segment them by 'group of hours' the orders were placed.

 

The above formula by @parry2k works nicely for 'group of hours' within which above logic applies but does not count user transactions who have only 1 transaction within a specifc 'group of hours'.

 

I am not sure if i am able to express properly. I did the same calculation on Excel and my result for sample should be as follows:

 

  Orders by users ordered more than onceOrder by users with only one orderTotal Orders
 12 to 4 AM 303
 12 to 4 PM 73643
 5 to 8 PM 101
 9 to 12 AM 112
Total 123749

 

However in a table in Power BI the results are following:

Screen2.png

It is not counting 4 transactions becasue they are occuring only once for a given user within a group. I cannot find the option to attach a sample data fil.e I will just copy the data relvant to the required mesaure below.

 

Data:

UserIDDate PurHoursHour Group
9686659511/1/2019 14:17 514 12 to 4 PM
9686659511/1/2019 14:30 514 12 to 4 PM
9686659511/1/2019 14:31 514 12 to 4 PM
9686659511/1/2019 17:22 517 5 to 8 PM
9686659511/1/2019 21:36 521 9 to 12 AM
14878188411/1/2019 0:48 40 12 to 4 AM
14878188411/1/2019 12:36 412 12 to 4 PM
14878188411/2/2019 13:13 413 12 to 4 PM
14878188411/1/2019 14:11 414 12 to 4 PM
5754400211/1/2019 0:47 30 12 to 4 AM
5754400211/1/2019 1:47 31 12 to 4 AM
5754400211/1/2019 12:30 312 12 to 4 PM

@parry2k

 

They both work fine at the aggregate level. But numbers doesn't look right when i group them within a bins of hours. I added calculated column to get hour from the 'date & time' field in the same table. And created hour bins by creating groups.

 

As you can see in the following screen:

Screen.png

The total here is correct as per my data but the sum of all the underlying values doesn't add up to the total there 3,257 transactions. This method of grouping worked perfectly when i use simple countrows without condition. 

 

I assumed that my approach was not correct and somehow it is only calculating one transaction per user and that's the reason of the difference.

 

Can you please help understand where I am wrong in this? Is it the grouping i need to do another way or to get this kind of grouping we need to calculate the transactions with another approach?

 

Thank you for the assiatnce.

Ahmed

 

 

rubinboer
Resolver II
Resolver II

Your Result = COUNTROWS(FILTER(YourTable,Yourtable[YourColumn] > 1))

This counts the total rows where the value is more than 1

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.