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
Tasos
Helper II
Helper II

Calculate the sum of a measure

Hello,

 

I need help with something I've spent a whole day to calculate.

 

I need to calculate (and not just to show) the total sum of a measure.

 

In the screenshot below, each SKU was sold multiple times during a period.

I have calculated the total number of cases (for example for SKU AB000ACL04-ELCL, Cases=10+20+30+6=66).

I have a separate table with the CartonQuantity, meaning the units per case per SKU (for the same SKU, there are 34Units per case).

Finally, I have multiplied the #of cases with the CartonQuantity (66*34=2,244 Units)

 

What I need is a measure that calculates and returns the total Units (2,244+0+0+0+220+80+...=X).

 

I could have done it as a column, however, I need it as a measure as I want it to be dynamic and be updated when I apply filters (period/ specific SKUs/etc)

 

Capture.JPG

Thank you

1 ACCEPTED SOLUTION
toddpbi
Helper II
Helper II

Hi there Tasos,

Try and use an iterator function like SUMX. SUMX creates a filter context by itterating every row of the table with row context, multiplies the column values and then sums them up.

Try writing the following measure (assuming your carton quantity table contains a single row for every SKU).
Make sure there is a relationship between SKU between both of your tables.

UnitsAsCases =
SUMX ( 'TableName', 'TableName' [ Cases ] * RELATED ( 'TableName' [CartonQuantity] )
)

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi Tasos,

 

Got it. Keep SKU's on the dimension level. So that, You have mapping with your fact table and the data will be filtered out based on the selection.

 

SKU - - > your table (SKU column) 

 

Your filter should be from the dimension and not from fact.

 

Pradeep

toddpbi
Helper II
Helper II

Hi there Tasos,

Try and use an iterator function like SUMX. SUMX creates a filter context by itterating every row of the table with row context, multiplies the column values and then sums them up.

Try writing the following measure (assuming your carton quantity table contains a single row for every SKU).
Make sure there is a relationship between SKU between both of your tables.

UnitsAsCases =
SUMX ( 'TableName', 'TableName' [ Cases ] * RELATED ( 'TableName' [CartonQuantity] )
)

@toddpbi

 

one more question; although what you proposed worked in my previous case, I don't have the output I want in a supplementary one.

 

I want to sum all these eachords that the sum of cartonords and the sum of palords are 0.

 

In my first attempt, it returns the difference between the eachords and the other two values (eachords-cartonords-palletordrs).

The second one returns the correct value per line (0 for the first line, 2,508 for the second, etc), however, the total is incorrect. 

 

Can you also give a hand on that? 

 

Capture.JPG

 

Thanks

@toddpb, Thanks for the quick reply. It seems like it is working.

 

@Anonymous, not sure I have understood your reply. 

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.