Forum Discussion
Display data for dates relative to date selected in table
We use Power BI to publish our financial statements (e.g. balance sheet, profit & loss, etc). Many of our statements also have a trailing 12-month version where it is the current month, and the previous 12 months. All of the statements are in tables. I would like to provide a date slicer so the user can select any month, and the financial statements will display for the selected month. It is correclty presenting the month selected, but I've been unable to determine how to have the trailing months present correctly. Each of the columns is a measure, which allows me to customize the order of the statement items, insert blank rows, etc.
Here is the measure for the selected month (trimmed due to character constraints in this post):
5 Replies
- AnonymousNot applicable
Anonymous this is pretty difficult to try to debug without any sample data to work with, but the thing that immediately jumps out to me in your second measure are the RevenueCalc/Revenue and COSCloudCalc/COSCloud variables.
I don't think you can reference a variable within a CALCULATE function as you are doing there. My understanding is that once the "Calc" variables have been declared and evaluated, they are treated as constants in subsequent variables, until a RETURN statement is reached. That is, they would not be affected by CALCULATE modifiers.
I would recommend combining the "calc" variables into a single step which contains the necessary date filter modifiers to select the previous month.
Enterprise DNA has an excellent video explaining the concept of "variables as constants", which I think is what you are running into here.
What does "Variables Are Constants" Really Mean?- AnonymousNot applicable
Anonymous , thank you for taking the time to look over this. I can confirm that those values do calculate correctly, it is only that they are not calculating for the correct timeframe.
- AnonymousNot applicable
Anonymous Did you watch the video I linked? I think it describes exactly what you are seeing here... Let me try to explain a different way...
Take your Revenue variable for example:
VAR Revenue = CALCULATE(RevenueCalc, REMOVEFILTERS('Date'), KEEPFILTERS(SelPeriod), USERELATIONSHIP('Date'[Date], 'Calendar'[Date]))The "KEEPFILTERS" modifier is what is supposed to be adjusting the timeframe. But it has no effect, because "RevenueCalc" is treated as a constant, and therefore cannot be affected by a CALCULATE modifier. You need to combine the Revenue and RevenueCalc variables into a single variable (and same with your COSCloud and COSOther variables).