cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mimi
Helper I
Helper I

max as a filter

Hi

 

I am trying to calculate sales based on the maximum invoice period, in case someone chooses multiple periods. here is my formula and it is not working. Any help will be appreciated.

 

Sales = CALCULATE(sum(Query1[SalesValue]);max(Query1[InvoicePeriod]))
 
2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Without going into whether there are any other issues with this approach, to get around the problem you have raised you'd just need to put it into a variable:

 

Sales = var filterDate = max(Query1[InvoicePeriod])
RETURN
CALCULATE(
     sum(Query1[SalesValue]);
     Query1[InvoicePeriod] = filterDate
)

You'll also need to specify what the filter condition is.  I've assumed you want records based on that date.  However you could use <= if you wanted to get all records on or before.

View solution in original post

Anonymous
Not applicable

I'd suggest creating a date table and having the slicer be based on that date table.  Then, for variable filterdate, do the max on the DateTime instead.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Without going into whether there are any other issues with this approach, to get around the problem you have raised you'd just need to put it into a variable:

 

Sales = var filterDate = max(Query1[InvoicePeriod])
RETURN
CALCULATE(
     sum(Query1[SalesValue]);
     Query1[InvoicePeriod] = filterDate
)

You'll also need to specify what the filter condition is.  I've assumed you want records based on that date.  However you could use <= if you wanted to get all records on or before.

View solution in original post

Hi Ross

 

Thank for replying.

However, I am noticing that if the FilterDate does not have values for that month, the value that is being produced is for other months.

 

For example, suppose the user selects Jan and Feb (represented as number 201801 and 201802). if Feb has no sales values, the result returned is for Jan. I do not want that. I prefer that the value that comes through = 0 or blank

Anonymous
Not applicable

I'd suggest creating a date table and having the slicer be based on that date table.  Then, for variable filterdate, do the max on the DateTime instead.

View solution in original post

Yes it worked thank you

Helpful resources

Announcements
PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Get Ready for Power BI Dev Camp

Microsoft named a Leader in The Forrester Wave

Microsoft received the highest score of any vendor in both the strategy and current offering categories.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Solution Authors
Top Kudoed Authors