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
Javierco
Helper I
Helper I

Best way to model inventories

Probably missing something very basic about how measures work. 

 

I have a measure to calculate inventory on hand based on table inventory_v2.

 

When reporting a table for August I get:

 

agosto.png

 

When reporting September, I get:

 

sept.png

 

Both tables seem to be ok. However when I select both months, I get:

 

august and sept.png

 

which shows data from both months, but when calculating totals only considers September data.

 

The expected result would have been to get a table identical to September since it is the latest month.

 

Would much appreciate your help in understanding why the difference vs expected and should I modify my measures to get the expected result.

 

Some additional info:

 

"label" column is a calculated column based on inventory price

 

Inventory on hand is calculated as follows:

 

 

inv_on_hand_v5 = 

VAR latest_date = CALCULATE(MAX(inventory_v2[inventory_date]))
VAR inv_currency = CALCULATE(SUMX(inventory_v2,(inventory_v2[inventory_amount]) / inventory_v2[relatedrate]), FILTER((inventory_v2),latest_date==inventory_v2[inventory_date]))
VAR inv_units = CALCULATE(SUMX(inventory_v2,(inventory_v2[inventory_qty])), FILTER((inventory_v2),latest_date==inventory_v2[inventory_date]))

RETURN inv_currency

 

 

 

1 REPLY 1
andhiii079845
Super User
Super User

This is the typical "total sum" problem with dax:
https://www.sqlbi.com/articles/why-power-bi-totals-might-seem-inaccurate/
YOU can fix it like this:

 

 

RETURN if(hasonefilter(label)=TRUE;inv_currency;X)

 

 

The problem can be that you choose with 

 

latest_date = CALCULATE(MAX(inventory_v2[inventory_date]))

 

only the last date in sept  in the last row. 

One idea:

 

inv_on_hand_v5 = 
VAR earlist_date = CALCULATE(MIN(inventory_v2[inventory_date]))
VAR latest_date = CALCULATE(MAX(inventory_v2[inventory_date]))
VAR inv_currency = CALCULATE(SUMX(inventory_v2,(inventory_v2[inventory_amount]) / inventory_v2[relatedrate]), FILTER((inventory_v2),latest_date>=inventory_v2[inventory_date])&& earlist_date<=inventory_v2[inventory_date]))
VAR inv_units = CALCULATE(SUMX(inventory_v2,(inventory_v2[inventory_qty])), FILTER((inventory_v2),latest_date==inventory_v2[inventory_date]))

RETURN inv_currency

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.