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
John117
New Member

Sum with filter and cross table

I have 2 tables, one with the date, customer name, and the gross sales and another table that is a selection of the most relevant customer by date, like this:

 

Table 1

DateCustomerGross Sales
01/06/2020X300
01/06/2020Y200
01/07/2020Y100
01/07/2020Z150

 

Table 2

DateCustomer
01/06/2020X
01/07/2020Y
01/07/2020X

 

I need to calculate the total sales of the most relevant customers, but it's not working. I'm using this formula:

 

Total gross = calculate(sum(Table1[Gross Sales]), filter(Table1, Table1[customer]=values(Table2[customer])))

 

The error message says 'MdxScript(Model) (4,102) Calculation error in measure: A table of multiple values was supplied where a single value was expected'

 

Could someone help me? I'm beginner in Power BI

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @John117 ,

 

VALUES() returns a single column table or a table of the same columns. In your scenario, VALUES(Table2[customer]) returns a table with a single column. Your problem is that a column cannot equal a table. You can use IN instead of “=”.


 

IN Creates a logical OR condition between each row being compared to a table. Note: the table constructor syntax uses curly braces. 'Product'[Color] IN { "Red", "Blue", "Black" }

 


The formula can be modified as follows:

 

Total gross 2 =
CALCULATE (
    SUM ( Table1[Gross Sales] ),
    FILTER ( Table1, Table1[customer] IN VALUES ( Table2[customer] ) )
)

 

The result is shown in the following figure:

sales.PNG

 

 

The above formula is limited to filtering customer names. If you also want to filter by date and customer name at the same time. You can write a calculated columns or a measure.

 

You can write your calculated column like so:

 

Total gross =
CALCULATE (
    SUM ( Table1[Gross Sales] ),
    FILTER (
        Table1,
        Table1[customer] = 'Table2'[customer]
            && Table1[Date] = Table2[Date]
    )
)

 

The result is shown in the following figure:

sales1.png

 

Or you can write your measure like so:

 

Total gross3 = 
VAR table3 =
    ADDCOLUMNS (
        Table2,
        "Total gross4", CALCULATE (
            SUM ( Table1[Gross Sales] ),
            FILTER (
                Table1,
                Table1[Customer] = Table2[customer]
                    && Table1[Date] = Table2[Date]
            )
        )
    )
RETURN
    SUMX ( table3, [Total gross4] )

 

 

The result is shown in the following figure:

sales2.png

 

You can check more details from here.

 

 

Best Regards,

Icey

 

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

3 REPLIES 3
Icey
Community Support
Community Support

Hi @John117 ,

 

VALUES() returns a single column table or a table of the same columns. In your scenario, VALUES(Table2[customer]) returns a table with a single column. Your problem is that a column cannot equal a table. You can use IN instead of “=”.


 

IN Creates a logical OR condition between each row being compared to a table. Note: the table constructor syntax uses curly braces. 'Product'[Color] IN { "Red", "Blue", "Black" }

 


The formula can be modified as follows:

 

Total gross 2 =
CALCULATE (
    SUM ( Table1[Gross Sales] ),
    FILTER ( Table1, Table1[customer] IN VALUES ( Table2[customer] ) )
)

 

The result is shown in the following figure:

sales.PNG

 

 

The above formula is limited to filtering customer names. If you also want to filter by date and customer name at the same time. You can write a calculated columns or a measure.

 

You can write your calculated column like so:

 

Total gross =
CALCULATE (
    SUM ( Table1[Gross Sales] ),
    FILTER (
        Table1,
        Table1[customer] = 'Table2'[customer]
            && Table1[Date] = Table2[Date]
    )
)

 

The result is shown in the following figure:

sales1.png

 

Or you can write your measure like so:

 

Total gross3 = 
VAR table3 =
    ADDCOLUMNS (
        Table2,
        "Total gross4", CALCULATE (
            SUM ( Table1[Gross Sales] ),
            FILTER (
                Table1,
                Table1[Customer] = Table2[customer]
                    && Table1[Date] = Table2[Date]
            )
        )
    )
RETURN
    SUMX ( table3, [Total gross4] )

 

 

The result is shown in the following figure:

sales2.png

 

You can check more details from here.

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Now it's working. Thank you so muck, @Icey !

 

lbendlin
Super User
Super User

Yes, VALUES() returns {X,Y}  from Table 2.  Don't you also want to filter by date? And correct your sample data in Table 2?

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.