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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
Anonymous
Not applicable

Need Help with Recursive Measure

Hello,
I need help with the following recursive measure, I've been trying unsuccessfully something like this:

Measure =
var x = CALCULATE(sum(GIACENZA[LQNTY]) , GIACENZA[ITNBR] = max('ITMRVA chiave'[ITNBR])) - sum(ORDERS[ORDER QTY])
return
CALCULATE ( x , FILTER ( ALL('Calendar'), 'Calendar'[Date] <= MAX ('Calendar'[Date] ) ) )

Thank you.


t0 (today)12
ITEM A   
ORDER QTY200100400
STOCK [LQNTY]1000blankblank
MEASURE800700300
ITEM B ....   
1 ACCEPTED SOLUTION
Anonymous
Not applicable

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
    )

yingyinr_0-1651829784397.png

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

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hello @Anonymous ,
I was trying to figure out if it was possible to:
- Show measure values in dates where I'm not having Orders/Stock
- Filter the measure for negative values (i.e. Delta <0)  without breaking up the logic behind the Measure.
BR,
Marco


Anonymous
Not applicable

I've developed this one, which seems to be working but NOT with multiple items.

Measure = CALCULATE (-sum(ORDERS[LQRES])+sum(GIACENZA[LQNTY]),
FILTER(ALLSELECTED('ORDERS'), IF(TODAY()>FIRSTDATE(ORDERS[Data Consegna]), TODAY(), ORDERS[Data Consegna]) <= max('Calendar'[Date]) ))
marcoproserpio_5-1651159849918.png

How can I solve the following problems with multiple items?

marcoproserpio_6-1651159916244.png

It's not executing separate calculation for different items, but aggregating them...

Thank you






 

 

 

Anonymous
Not applicable

Hi @Anonymous ,

Please update the formula of your measure as below and check whether that can return the correct result.

Measure =
SUM ( GIACENZA[LQNTY] )
    - CALCULATE (
        SUM ( ORDERS[LQRES] ),
        FILTER (
            ALLSELECTED ( 'ORDERS' ),
            IF (
                TODAY () > FIRSTDATE ( ORDERS[Data Consegna] ),
                TODAY (),
                ORDERS[Data Consegna]
            )
                <= MAX ( 'Calendar'[Date] )
        )
    )

If the above one can't help you get the desired result, please provide some sample data in your tables GIACENZA and ORDERS (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

Anonymous
Not applicable

Thank you for your answer. It's not contextualizing items still. 
Here is the .pbix --> https://easyupload.io/rvndjm
BR,
Marco

Anonymous
Not applicable

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
    )

yingyinr_0-1651829784397.png

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

Anonymous
Not applicable

Hello @Anonymous ,
Works perfectly! 
Thank you.
BR,
Marco

Helpful resources

Announcements
Fabric Data Days is here Carousel

Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.