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
Anonymous
Not applicable

how to calculate the number of buying for customers in one table

hello, I have one table like this

id customerID salesdate  salesamount

001   10001     20200101   200

002   10001     20200101   300

003  10003      20200102   400

004    10003    20200203    1000

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

I need to create a measure to show the frequency of purchase for customers during a selected period , like this
frequency of purchase=switch( true(), count(customerID)=1, "one time", "more than one time"). but this measure can not work.

please guide me how to create this measure to show the frequency of purchase  for each customer

3 ACCEPTED SOLUTIONS
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

Try it.

frequency of purchase = 
var _count=CALCULATE(COUNT('Table'[customerID]),FILTER(ALLSELECTED('Table'),[customerID]=MAX('Table'[customerID])))
return 
IF(_count=1,"one time", "more than one time")

The final show:

vyalanwumsft_0-1659596502727.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

Allselected() is to make the result vary according to the selected slicer. max(): [A]=max([A]) is also a method of grouping; here refers to the ID to calculate the count for the group.

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

I am so sorry late reply due to account issues; you could create another measure.

 

count = CALCULATE(DISTINCTCOUNT('Table'[customerID]),FILTER('Table',[frequency of purchase]="one time"))

 

The final show:

vyalanwumsft_0-1660815927606.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

I am so sorry late reply due to account issues; you could create another measure.

 

count = CALCULATE(DISTINCTCOUNT('Table'[customerID]),FILTER('Table',[frequency of purchase]="one time"))

 

The final show:

vyalanwumsft_0-1660815927606.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

Allselected() is to make the result vary according to the selected slicer. max(): [A]=max([A]) is also a method of grouping; here refers to the ID to calculate the count for the group.

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

Try it.

frequency of purchase = 
var _count=CALCULATE(COUNT('Table'[customerID]),FILTER(ALLSELECTED('Table'),[customerID]=MAX('Table'[customerID])))
return 
IF(_count=1,"one time", "more than one time")

The final show:

vyalanwumsft_0-1659596502727.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thanks a lot! Now I understand it. Could I ask you further about this question? Now I can get the number of purchase frequency for each customer during the selected time period, and then I need to calculate for this time period, how many customers purchased only once, and how many purchased more than once.

Anonymous
Not applicable

also I found if I use a date slicer, the result can not change with slicer. 

Anonymous
Not applicable

Thank you a lot!

 

May I ask you why you use 

ALLSELECTED('Table')

but not use only  'Table'. and why you use 

[customerID]=MAX('Table'[customerID])

Thanks again!

amitchandak
Super User
Super User

@Anonymous , refer to my video on segmentation. Use the count measure in place of the sum measure I used. Your Group by /values is customer

Dynamic segmentation -Measure to Dimension conversion: https://youtu.be/gzY40NWJpWQ

 

Bucket/Segment code
measure
Measure = Count(Table[id])

 

new Table
bucket = Generateseries(1,100,1)

 

 

new Measure
Countx(filter(Values(Table[customerID]), [Measure] = max(bucket[Value])), [customerID])

 

Buket should be used in visual

 

else

 

Sumx(Values(bucket[Value]) ,calculate( Countx(filter(Values(Table[customerID]), [Measure] = max(bucket[Value])), [customerID]) ))

 

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.