cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Calculate Purchase frequency

Hi everyone, I cannot understand why the total does not SUM correctly.
In the following table I am making measurements of:
Id_Name = Distinctcount (Table1 [Id_Name]) ... OK
Sales Check = Distinctcount (Table1 [Id_SalesCheck]) ... OK
here I can not show what is seen in the table.
2 or more Purchas = If (Sales Check > 1, Distinctcount (Table1 [Id_Name]), BLANK())
I tried SUMX but the result was an out-of-itself number.
SUMX (Table1, Distinctcount (Table1 [Id_Name]))

 

I try to do my best but I'm really frustrated, I need helpCapture.JPG

This next table make in Excel and Show how I want to see, really I want to correctly sum total.

 

Capture1.JPG

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Microsoft
Microsoft

Re: Calculate Purchase frequency

Hi , @GKs 

Please check this sample file:
pbix attached

 

Try measure as below:

Measure = SUMX(VALUES('Table1'[Id_Name]),'Table1'[2 or more Purchas])

 

33.png

 

Best Regards,
Community Support Team _ Eason
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

4 REPLIES 4
Highlighted
Super User II
Super User II

Re: Calculate Purchase frequency

Try something like this:

 

Measure 2 = 
COUNTX(
    FILTER('Table',
    'Table'[Sales Check] > 1
    ),
    'Table'[Sales Check]
)

 

The issue is your measure works fine and it is doing what you asked. Remember measures are recalculated for every place they are used.  The total lines do not have a different formula that just sums what is above it. It recalculates the measure based on the filter context of where it is, which is the total line with no filters for the ID. So, in your total, the measure is recalculating and doing this:

 

  1. Is sales check > 1? Well, what is sales check on the total line? It is DistinctCount(table) - on the total line, that is the entire table. So the distinct count is 158. So yes, 158 > 1, so the result is True.
  2. Therefore return DistinctCount(table) which is 158, and that is what you see.

If you need further help, please post usable data via the links below. We cannot use images for data samples.

How to get good help fast. Help us help you.
How to Get Your Question Answered Quickly
How to provide sample data in the Power BI Forum



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Highlighted
New Member

Re: Calculate Purchase frequency

Basically, there's a filter context on each row of your table, e.g. ID_Name = 1 is the filter context on your first row. But the issue is with the Total as there's no such filter on that. 

 

Here you can try use HASONEVALUE to check if Id_name has single value. If it's return false, it means you are on "Total" row, which means there's no Id_name filter on that and it returns all values. 

 

I might suggest you take a look below, which might help. 

https://community.powerbi.com/t5/Community-Blog/Fixing-Total-Errors-In-Power-BI-I-Know-It-Can-Be-Fru...

Highlighted
Super User IV
Super User IV

Re: Calculate Purchase frequency

@GKs , Try like

countx(filter(summarize(Table1,Table1[id],"_1",[Sales Check]),[_1]>1),[id])


Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
My Recent Blog -Week is not so Weak Connect on Linkedin

Proud to be a Super User!

Highlighted
Microsoft
Microsoft

Re: Calculate Purchase frequency

Hi , @GKs 

Please check this sample file:
pbix attached

 

Try measure as below:

Measure = SUMX(VALUES('Table1'[Id_Name]),'Table1'[2 or more Purchas])

 

33.png

 

Best Regards,
Community Support Team _ Eason
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

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Upcoming Events

Upcoming Events

Wondering what events you could join or have an event to promote yourself? Check out our Upcoming Events.

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

We are thrilled to announce we will begin running a monthly webinar series named Power BI Dev Camp.

Top Solution Authors
Top Kudoed Authors