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
Anonymous
Not applicable

DAX command to sum individual sites in a matrix?

Hello,

 

I have the following matix. I am trying to create a column which shows the total amount of a specific product produced at the Ship To location. In this case MEH and OX.

 

The SKU column shows the quantity that has been shipped from Cape to the respective site. In the "Site Produces" column I want to display specifically how much the respective Ship To location produces of the SKU. The way I have it showing in the image below is by using the Calculate function to filter by the site OX. 

 

The function is as follows: 

 

OX Produces = CALCULATE ( SUM ( 'table'[SKU_quantity] ), ALLEXCEPT('table','table'[prod_name]), 'table'[Ship To] = "OX")

 

 

This does what I need but only for the OX site. Is it possible to have this function change within the matrix for each specific Ship To location, for example, when I expand to MEH, I will see the "Site Produces" value for MEH?

 

 Matrix.jpg

 

Thanks in advance!

5 REPLIES 5
Anonymous
Not applicable

[Measure] =
CALCULATE (
SUM ( 'table'[SKU_quantity] ),
VALUES( 'table'[prod_name] ),
VALUES( 'table'[Ship To] )
ALL('table' )
)
Greg_Deckler
Super User
Super User

@Anonymous - So normally you would create a VAR __shipto = MAX('Table'[Ship to]) and you would use that in your filter.

 

If that does not help, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler  Is this supposed to be a filter in the CALCULATE function?

 

I tried the follwing:

_Site Produces = CALCULATE (SUM('table'[SKU_quantity]),ALLEXCEPT('table','table'[prod_name]),[_Var_ShipTo]) 

 

This gives me the error "A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expression. This is not allowed." 

@Anonymous - I guess I was thinking:

 

OX Produces = CALCULATE ( SUM ( 'table'[SKU_quantity] ), ALLEXCEPT('table','table'[prod_name]), 'table'[Ship To] = Var_Ship_To)

 

I don't tend to use CALCULATE


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Anonymous ,

 

See if this works.

 

Produces = CALCULATE ( SUM ( 'table'[SKU_quantity] ), ALLEXCEPT('table','table'[prod_name])

 

The filter context should work for each shipto site.

 

Regards,

Harsh Nathani 

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.

Top Solution Authors