Forum Discussion
Need Help with Recursive Measure
- Anonymous4 years ago
Hi Anonymous ,
I updated your sample pbix file(see attachment) for you, please check whether that is what you want. You can update the formula of Measure as below:
MEASURE = VAR _selitnbr = SELECTEDVALUE ( 'ITEM_KEY'[ITNBR] ) VAR _stqty = CALCULATE ( SUM ( 'STOCK'[STOCKQTY] ), FILTER ( ALLSELECTED ( 'STOCK' ), 'STOCK'[ITNBR] = _selitnbr ) ) VAR _minstdate = CALCULATE ( MIN ( 'STOCK'[Date] ), FILTER ( ALLSELECTED ( 'STOCK' ), 'STOCK'[ITNBR] = _selitnbr ) ) VAR _maxorddate = CALCULATE ( MAX ( 'ORDERS'[Date] ), FILTER ( ALLSELECTED ( 'ORDERS' ), 'ORDERS'[ITNBR] = _selitnbr ) ) VAR _seldate = SELECTEDVALUE ( 'Calendar'[Date] ) VAR _culordqty = CALCULATE ( SUM ( 'ORDERS'[ORDERSQTY] ), FILTER ( ALLSELECTED ( 'ORDERS' ), 'ORDERS'[ITNBR] = _selitnbr && 'ORDERS'[DATE] <= _seldate ) ) RETURN IF ( _seldate < _minstdate || _seldate > _maxorddate, BLANK (), CALCULATE ( SUM ( STOCK[STOCKQTY] ), ALLSELECTED ( 'Calendar'[Date] ) ) - _culordqty )If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.
How to upload PBI in Community
Best Regards
Hi Anonymous ,
I updated your sample pbix file(see attachment) for you, please check whether that is what you want. You can update the formula of Measure as below:
MEASURE =
VAR _selitnbr =
SELECTEDVALUE ( 'ITEM_KEY'[ITNBR] )
VAR _stqty =
CALCULATE (
SUM ( 'STOCK'[STOCKQTY] ),
FILTER ( ALLSELECTED ( 'STOCK' ), 'STOCK'[ITNBR] = _selitnbr )
)
VAR _minstdate =
CALCULATE (
MIN ( 'STOCK'[Date] ),
FILTER ( ALLSELECTED ( 'STOCK' ), 'STOCK'[ITNBR] = _selitnbr )
)
VAR _maxorddate =
CALCULATE (
MAX ( 'ORDERS'[Date] ),
FILTER ( ALLSELECTED ( 'ORDERS' ), 'ORDERS'[ITNBR] = _selitnbr )
)
VAR _seldate =
SELECTEDVALUE ( 'Calendar'[Date] )
VAR _culordqty =
CALCULATE (
SUM ( 'ORDERS'[ORDERSQTY] ),
FILTER (
ALLSELECTED ( 'ORDERS' ),
'ORDERS'[ITNBR] = _selitnbr
&& 'ORDERS'[DATE] <= _seldate
)
)
RETURN
IF (
_seldate < _minstdate
|| _seldate > _maxorddate,
BLANK (),
CALCULATE ( SUM ( STOCK[STOCKQTY] ), ALLSELECTED ( 'Calendar'[Date] ) ) - _culordqty
)
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.
How to upload PBI in Community
Best Regards
Hello Anonymous ,
Works perfectly!
Thank you.
BR,
Marco