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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.