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
yasmin
Frequent Visitor

POWERBI: SUM IF BETWEEN TABLES

Hi guys, i think what i'm trying to do may be simple, but i'm not finding a way to get it right. I am trying to do the equivalent of a sumif in excel. I have the following tables:

STORES 
storeMANAGER
AM1
BM2
CM3
DM4

 

w_PRODUCTS
PRODUCTPROD_NAME
P1ABCD
P2DEFG
P3GHIJ
P4KLMN
P5OPQR
......

 

STOCK NETWORK
PRODUCTSTOREQTY
P1A2
P1B1
P1C2
P1D0
P2A1
P2B1
P2C1
P2D3
..... 

 

 

and I want the following table with two collums, the first showing the stock of the product in the specific store from that row, and the second collum with the sum of everything from that product(in that row) within all the stores. 

 

Storeproductstock (store)stock(all stores)
AP125
BP115
CP125
DP105
AP216
BP216
CP216
DP236
AP337
BP327
CP317
DP317

 

When I tried the second collum it return values from the store from the row only, not the sum from all of them

Thanks

1 ACCEPTED SOLUTION

 

Hi @yasmin

 

You should be able to create a measure thusly:

 

Count All Stores = CALCULATE(SUM(Stock[QTY]), ALL(Store[store]))

Capture.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Hope this helps

David

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

@yasmin what you need to do is use all except

 

 

calculate(sum(table1[qty]), allexcept(table1, table1[product])

 

https://msdn.microsoft.com/en-us/query-bi/dax/allexcept-function-dax

Here is the data model @dedelman_clng

 

DATADATA

 

@Anonymous when i use all except this happens:

 

ALLEXCEPTALLEXCEPT

Anonymous
Not applicable

@yasmin my bad, you need to use store instead of product in the formula

 

calculate(sum(table1[qty]), allexcept(table1, table1[store])

 

Hi @yasmin

 

You should be able to create a measure thusly:

 

Count All Stores = CALCULATE(SUM(Stock[QTY]), ALL(Store[store]))

Capture.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Hope this helps

David

Thank you guys! It worked! 😃

dedelman_clng
Community Champion
Community Champion

Please share a picture of your data model - with the correct modelling the calculation should be straightfoward.

The tables are just like I presented above

You did not "present" the data showing the relationship between the tables.  The best approach is a screenshot of the "model" page in your PowerBI file.

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.