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
Anonymous
Not applicable

Measure only works when a column is filtered

I have a measure which I want to return the amount we have available in stock of a product.

 

Since we have a history per product per day, I'd want it to return the amount for the last day or whichever period we're dealing with (for example, 31/12/2020 if I have filtered on the year 2020, or today if I have no filter on the date, etc), but so far, it only works if I filter the date.

 

The measure goes :

Latest Amount := CALCULATE (
    [_Quantity_Sum];
    FILTER (
        Fact_Stock;
        Fact_Stock[Date of Stock]
            = MAX ( 'Calendar'[Day in year] )
    )
)

 

And like I said, it gives no result if I only select the product column and this measure, but it will give me a result if I filter on the month or on the day. Any idea on how to make it work with no filter ?

 

Kindly,

Nossair

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , That need a row context to get it. Try this , but it will only give data for max date selected

 

Latest Amount :=
var _max = maxx(allselected('Calendar'),'Calendar'[Day in year])
return
CALCULATE (
[_Quantity_Sum];
FILTER (
Fact_Stock;
Fact_Stock[Date of Stock]
= _max
)
)

Anonymous
Not applicable

Hi @amitchandak ,

 

Thanks for your answer, however, indeed, it still doesn't give a result for when I don't filter on the date. Do you have an idea on why that's the case ? I'm still rather new to DAX and I can't quite put my finger on it.

 

Kindly,

Nossair

 

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.