cancel
Showing results for
Did you mean:
Highlighted
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

 Date Customer Gross Sales 01/06/2020 X 300 01/06/2020 Y 200 01/07/2020 Y 100 01/07/2020 Z 150

Table 2

 Date Customer 01/06/2020 X 01/07/2020 Y 01/07/2020 X

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

Accepted Solutions
Highlighted
Community Support

## Re: Sum with filter and cross table

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:

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:

Or you can write your measure like so:

``````Total gross3 =
VAR table3 =
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:

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.

3 REPLIES 3
Highlighted
Community Champion

## Re: Sum with filter and cross table

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?

Highlighted
Community Support

## Re: Sum with filter and cross table

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:

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:

Or you can write your measure like so:

``````Total gross3 =
VAR table3 =
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:

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.

Highlighted
New Member

## Re: Sum with filter and cross table

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

Announcements

#### August 2020 Community Challenge: Can You Solve These?

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

#### Community Blog

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

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

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

Top Solution Authors
Top Kudoed Authors