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
marcoproserpio
Helper II
Helper II

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

Hi @marcoproserpio ,

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

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

View solution in original post

6 REPLIES 6
marcoproserpio
Helper II
Helper II

Hello @v-yiruan-msft ,
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


marcoproserpio
Helper II
Helper II

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






 

 

 

Hi @marcoproserpio ,

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

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

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

Hi @marcoproserpio ,

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

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

Hello @v-yiruan-msft ,
Works perfectly! 
Thank you.
BR,
Marco

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.

Top Solution Authors