I think I'm missing an ALL() somewhere.

alfranco17

Board Regular
Joined
Apr 14, 2013
Messages
198
Hi.

I'm trying to get the value of non-expired inventory for a period.

This is the expected result:
1623947324218.png

And this is what I get with the relationship. As soon as I connect Periods to Inventory (there are several measures that require it, and this non-expired was kind of a latter request) I get only one month.:
1623947356503.png

I believe I'm missing an ALL() somewhere, but I am really stuck.

Would you please help?

No relationship
With relationship


Excel Formula:
Available CALCULATE :=
VAR __PeriodStart =
    MIN ( Months[Start] )
VAR __PeriodEnd =
    MAX ( Months[Start] )
RETURN
    CALCULATE (
        SUM ( Inventory[Quantity] ),
        FILTER (
            Inventory,
            AND (
                Inventory[Valid from] <= __PeriodEnd,
                Inventory[Valid to] >= __PeriodStart
            )
        )
    )

Or this one:


Code:
Available SUMX:=VAR __PeriodStart =
    MIN ( Months[Start] )
VAR __PeriodEnd =
    MAX ( Months[End] )
RETURN
SUMX(
        FILTER (
            Inventory,
            AND(Inventory[Valid from] <= __PeriodEnd,
                Inventory[Valid to] >= __PeriodStart)
        ),
        Inventory[Quantity]
    )

1623946870611.png

1623946590709.png


But as soon as I define a relationship, it only gets that one month:
1623946929148.png


1623946950950.png


Thanks.
Armando.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I don’t know if there is a way of doing it using just DAX, but my thoughts would be to blow out inventory table date range so that you have a row for each month and then using that in your data model. You can do that using Power Query, instructions can be found here > Generating Rows by Month for Date Ranges
 
Upvote 0
Solution

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top