Forum Discussion

GKs's avatar
GKs
Frequent Visitor
6 years ago
Solved

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 help

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

 

 

 

  • Hi , GKs 

    Please check this sample file:
    pbix attached

     

    Try measure as below:

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

     

     

    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.

4 Replies

  • edhans's avatar
    edhans
    Community Champion

    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

  • RoastedPork's avatar
    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-Frustrating/ba-p/552929

  • GKs , Try like

    countx(filter(summarize(Table1,Table1[id],"_1",[Sales Check]),[_1]>1),[id])
  • v-easonf-msft's avatar
    v-easonf-msft
    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])

     

     

    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.