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
GKs
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
v-easonf-msft
Community Support
Community Support

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
v-easonf-msft
Community Support
Community Support

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.

amitchandak
Super User
Super User

@GKs , Try like

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

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...

edhans
Super User
Super User

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

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.