Forum Discussion
Max Month -1
Hi ,
Thanks !
11 Replies
- AmiraBedh
Super User
In your case MaxMonthValue calculation for "Max Month -1" subtracts 1 from the maximum year-month number found in the data that meets the condition [UsagesCount] >= 1. This works well in an unfiltered context because it works on the entire dataset.
However, when you apply a filter to a specific month, this changes the dataset that MaxMonthValue operates on, likely resulting in a different maximum year-month number or potentially no suitable data at all after the subtraction. This is especially true if the filtered month is the actual maximum month in your dataset since subtracting one would point to a month that's not included in your filter context
Max Month -1 Usages = VAR MaxMonthValue = CALCULATE( MAX('Date'[Year Month Number]) - 1, ALL('Date'), // Ignores the filter context for this calculation 'Date'[UsagesCount] >= 1 ) RETURN CALCULATE( [Total Kwh], 'Date'[Year Month Number] = MaxMonthValue )- JamesBurke
Helper III
Thanks for the Quick response,
I'm getting a Function Placeholder is being used Error ?
- AmiraBedh
Super User
Can you share your dataset ?
- AnonymousNot applicable
Hi JamesBurke ,
How is your 'Date'[Year Month Number] defined?
Try using the calculated column below to make sure it is a consecutive number.Year Month Number = 'Date'[Year] * 12 + 'Date'[Month Number]Best Regards,
Gao
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!How to get your questions answered quickly--How to provide sample data in the Power BI Forum--China Power BI User Group
- JamesBurke
Helper III
Hi ,
My Year Month Number is a consecutive number, I have a database pulled from Sql
- AnonymousNot applicable
Hi JamesBurke
Take the sample data you gave as an example:202001 - 1 = 202000 (not 201912). This is why the empty set is returned, because [Year Month Number] does not contain these values.
Try creating a column using my logic above.
201912 --> 2019*12+12=24240
202001 --> 2020*12+1=24241
24241-1=24240Best Regards,
Gao
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!How to get your questions answered quickly--How to provide sample data in the Power BI Forum--China Power BI User Group