Skip to main content
cancel
Showing results for
Search instead for
Did you mean:

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Resolver I

## From inventory position to inventory range with correct totals

Hi all,

I have a table with inventory positions per week, and sometimes a week is missing.

I want a matrix table in Power BI with the inventory positions per day, where also the total inventory position per day is correct.
I created a small example dataset with just two articles, and created this measure using LASTNONBLANK.

The totals are sometimes incorrect (red) and correct (green) summed.

Can you help so that also the totals in the red area is correctly summed?

1 ACCEPTED SOLUTION
Community Support

You can try the following methods.

``````Measure =
VAR _a =
ADDCOLUMNS ( DISTINCT ( ALL ( 'fact Stock positions'[Article code] ) ),
"Date", CALCULATE ( MAX ( 'fact Stock positions'[Date] ),
FILTER ( ALL ( 'fact Stock positions' ),
[Article code] = EARLIER ( 'fact Stock positions'[Article code] )
&& [Date] <= MAX ( 'dim Date'[Date] ) ) ) )
VAR _b =
SUMX ( _a,
CALCULATE ( SUM ( 'fact Stock positions'[Quantity in pcs] ),
FILTER ( ALL ( 'fact Stock positions' ),
[Article code] = EARLIER ( 'fact Stock positions'[Article code] )
&& [Date] = EARLIER ( [Date] ) ) ) )
RETURN
IF ( ISINSCOPE ( 'fact Stock positions'[Article code] ),
[Stock position to range measure],
_b
)``````

Is this the result you expect?

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

1 REPLY 1
Community Support

You can try the following methods.

``````Measure =
VAR _a =
ADDCOLUMNS ( DISTINCT ( ALL ( 'fact Stock positions'[Article code] ) ),
"Date", CALCULATE ( MAX ( 'fact Stock positions'[Date] ),
FILTER ( ALL ( 'fact Stock positions' ),
[Article code] = EARLIER ( 'fact Stock positions'[Article code] )
&& [Date] <= MAX ( 'dim Date'[Date] ) ) ) )
VAR _b =
SUMX ( _a,
CALCULATE ( SUM ( 'fact Stock positions'[Quantity in pcs] ),
FILTER ( ALL ( 'fact Stock positions' ),
[Article code] = EARLIER ( 'fact Stock positions'[Article code] )
&& [Date] = EARLIER ( [Date] ) ) ) )
RETURN
IF ( ISINSCOPE ( 'fact Stock positions'[Article code] ),
[Stock position to range measure],
_b
)``````

Is this the result you expect?

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

## Helpful resources

Announcements

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

#### Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors