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.
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:
When reporting September, I get:
Both tables seem to be ok. However when I select both months, I get:
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
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
Proud to be a Super User!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
104 | |
95 | |
80 | |
67 | |
62 |
User | Count |
---|---|
147 | |
109 | |
107 | |
85 | |
63 |