I am using the following calculation in my cube to get balances for P&L and Balance Sheet accounts. this is working fine but the problem is that this code doesn't work if I have filters on the date dimension.
For example, let's say I am looking at amounts for the 4 quarters for 2014 - the sub-total in this case for balance sheet accounts would be the Amount in 2014 Q4(and the calculation works correctly). However, if when am looking at say two quarters Q1 and Q2 for 2014, the calculation still shows the sub-total as the Amount in 2014 Q4 whereas the correct value should be Amount in 2014 Q2. I have pasted a screen shot of Excel pivot table also.
CASE [Accounts].[Account Type].CurrentMember.MemberValue
WHEN 'Balance Sheet'
THEN ([Dates].[Hierarchy].currentMember.lastChild, [Measures].[Measures].[Amount])
ELSE Amount
END
Any idea how to achieve this?
Related
I am trying to combine two tables in an SSAS cube and filter one of the tables depending on a value selected by the user in a pivot table from an Excel file connected to the cube. Is this possible and if so how do I do it?
To describe in more detail, I have two tables: history and forecast. For history there is only one set of records for each time period, but there are many forecasts for most periods. When a user selects (in the Excel pivot) a particular forecast version to view, I want to show them all of the forecast records available for that forecast and also history but only for periods that preceded the forecast.
So for example if a user today selects (in the Excel pivot) forecast 1, produced in 2021 Q3, the following is where the records come from:
2021 Q1 - history
2021 Q2 - history
2021 Q3 - forecast
2021 Q4 - forecast
2022 Q1 - forecast
2022 Q2 - forecast
but if a user today selects forecast 2, produced in 2022 Q1, the following is where the records come from:
2021 Q1 - history
2021 Q2 - history
2021 Q3 - history
2021 Q4 - history
2022 Q1 - forecast
2022 Q2 - forecast
Hopefully its clear what I'm trying to accomplish. If this approach won't work but there is another way to accomplish this, please let me know.
Thank you in advance for your help!
Create a new table that is unconnected in the model for the filter that lists your forecast periods. Mine here has a new forecast every quarter.
The start date is the column used to determine whether to use History or Forecast in these DAX measures:
Actual Value = IF(HASONEVALUE('Filter'[Period]),
CALCULATE( SUM(History[Value]), History[Date] < MAX('Filter'[Start date]) ),
"Select quarter")
Forecast Value = IF(HASONEVALUE('Filter'[Period]),
CALCULATE( SUM(Forecast[Forecast]), Forecast[Date] >= MAX('Filter'[Start date]) ),
"Select quarter")
Actual or Forecast Value = IF(HASONEVALUE('Filter'[Period]),
[Actual Value] + [Forecast Value],
"Select quarter")
And here's what it looks like in Excel:
Right now the problem with my code is that it counts each month as a new aggregation, meaning that January and February will contain activity for the same account in both months. I only need the monthly activity for each month at the level of each account.
Right now where for example the activity for Account A = 100 for January and activity for Account A = 25 in February, my query shows activity in February for account A as 125 when I would like it to be returned as A = 100 for January and A = 25 for February.
Is this clear? If I use for example (YEAR(date_column)) the aggregation at the annual level is accurately represented. This approach however does not allow me to provide a monthly breakdown of the data. If I add a second column to get the "Month" values from the date e.g: (MONTH(date_column)), the numbers are aggregated month over month and not at the month level alone.
First off its been a long week and I'm having a moment e.g. I just can't figure this out but I know its straight forward.
I have a CTE with a query for a GL Detail and one for Budget which are bought together to display all the details needed for a report.
For example the GL detail bring back the actual amount from a date range such as 2019-01-01 and 2019-04-01
and the budget part brings back the budget for each month so the date range is 2019-01-01 and 2019-12-01 as I need to sum up the total budget in a report.
Using an iif expression in SSRS the report shows the actuals up to the month a user select (there is on a to_date parameter)such as April then the report shows actual from Jan and then budget from May to Dec. I need to show the total of budget for the 12 month which is straight forward as I have bought each month amount back.
My question is I need to sum the GL actual amount for the months selected in by the user Jan to April and the remaining budget amounts May to Dec. For some reason I just can't work it out in my head.
Edit - I'm using
postgresql
SSRS - Microsoft SQL Server Reporting Services
columns are in GL is gldetail.amount and for Budget budget.amount_budget - I have a column in both gldetail and budget queries which is called post_date.
Worked it out -
,case
when src.post_date <= src._to_date then src.amount
when src.post_date > src._to_date then src.amount_budget
end as actual_budget_total
Then in the report sum the actual_budget_total
I'm using a calculated member for "previous period" as:
Case
// Test for current coordinate being on (All) member.
When [<<Target Dimension>>].[<<Target Hierarchy>>].CurrentMember.Level Is
[<<Target Dimension>>].[<<Target Hierarchy>>].[(All)]
Then "NA"
Else (
ParallelPeriod
(
[<<Target Dimension>>].[<<Target Hierarchy>>].[<<Target Level>>],
<<Number of Periods>>,
[<<Target Dimension>>].[<<Target Hierarchy>>].CurrentMember
),
[Measures].[<<Target Measure>>]
)
End
// This expression evaluates the difference between the value of the numeric
// expression in the previous period and that of the current period.
(snippet code taken directly from Microsoft suggestion)
It works as expected but when presenting the Totals I get the whole Year total, even if only some months are selected on rows.
So, if I select say year 2015, months Jan to Jun, I get the six correct values for 2014 months but a 2014 grand total instead of the sum of the six presented values.
Any way to get the "correct" sum value? By correct I mean the sum of the selected rows.
Edited to add the actual code:
Case
When [Dim Time].[Calendar].CurrentMember.Level Is [Dim Time].[Calendar].[(All)]
Then "NA"
Else (ParallelPeriod([Dim Time].[Calendar].[Year],
1,
[Dim Time].[Calendar].CurrentMember),[Measures].[Sales])
End
My Dim Time.Calendar has Year-Month-Day as levels. Easy enough :)
When selecting some months the Year total is the Grand total of the year, not the total of the selected months.
When selecting some days, the Month total is the Grand total of the month, not the total of the selected days.
Edited to add example:
Year Month Day Sales previous year Sales
2015 04 03 74,154.56 € 135,156.41 €
Total 04 2,617,045.75 € 135,156.41 €
Total 2015 37,696,665.69 € 135,156.41 €
(unsure if I should post an answer because it's not yet solved, but seems I found the right direction)
Using the suggestions here I defined a dynamic set (at cube definition time using MS SAS):
CREATE DYNAMIC SET CURRENTCUBE.[DynSet] AS [Dim Time].[Calendar]
and a Calculated member (on Excel, easier to test diferent syntax):
count([DynSet])
Now I get 1 as value on all rows, individual ones, subtotals, totals ... instead of the expected days of the selected month and the total sum.
Maybe someone with better MDX knowledge can develop it further.
I added also CM using the examples of the post count(descendants and count(existing( ... of the original [Dim Temps].[Calendar] and this is what I get:
Year Month Day Previous sales Sales CountExisting CountDescendants CountDays
2015 04 03 74,154.56 € 135,156.41 € 1 1 1
04 132,992.88 € 152,179.24 € 1 1 1
05 130,651.80 € 128,971.65 € 1 1 1
Total 04 2,617,045.75 € 416,307.30 € 31 31 1
Total 2015 37,696,665.69 € 416,307.30 € 365 365 1
I cannot understand how to use the new dynamic set as I'm not able to access its components, I expected [DynSet].[Year] [Month] and [Day] to exist so I could use them on my previous period expressions but they don't, so unsure on how to use it for my purpose.
Thks
Edited:
Tried to define
CREATE DYNAMIC SET CURRENTCUBE.[DynSet] AS [Dim Time].[Calendar].[Day]
and now my last column i.e. count([DynSet]) has a value of 3 for all lines.
Still no idea how to use [DynSet] levels ...
It took me almost two weeks, lots of searching hours and a dozen diferent forums, but finally I got a decent answer that solved the problem.
Take a look here
In brief, add a named calculation (not a calculated member) and scope the formula
SCOPE([Measures].[Previous_Sales]);
SCOPE([Dim Time].[Calendar].[Day].MEMBERS);
THIS = ([Measures].[Sales], ParallelPeriod([Dim Time].[Calendar].[Year])) ;
END SCOPE;
END SCOPE;
Simple enough once you know it!
I have two reports, one that is updated monthly from the source, and one that is updated once per week.
I have a KPI report that I want to show red/green indicators if the report is updated this month/this week.
The last updated date is stored in a table and is loaded into QlikView. QVD_Id is the id of the QV report.
The monthly report is beeing updated around the 10th each month. I have created this set analysis that seems to be "almost" working.
=if(Max({<Day=, Date=, QVD_Id={1}, MonthCounter={"<=$(#max(MonthCounter))"}>} num(Date(Updated))-1,00) >= num(Dato),0,1)
What I ultematly want for this indicator, is for it to be red if has not been updated within a month, or actually if its not updated within the 6th working day of the month it should be red(But this requered som additions to the dimensions that I can do later).
I tried to do the same for the weekly report, but its not working:
=if(Max({<Day=, Date=, QVD_Id={2}, WeekCounter={"<=$(#max(WeekCounter))"}>} num(Date(Updated))) >= num(Dato),0,1)
What I want with the weekly updated report, is that it should be red if it's not updated by the 2nd day of the week(Tuesday).
Example of the facttable used:
QVD_Id TotalLoad LoadYear LoadMonth LoadDay LoadHour Updated Date_Lnr Source
1 200000 2014 2 5 10 .02.2014 10:56:31 19759 Source1
WeekCounter is 58 this week, and MonthCounter is 2. (WeekCounter is just continiuing from last year but that does not matter here).
Hope any of you have some more experience then me with this and can find a solution for this.
i think this is close to what you want:
// check is date less than the 6 in the month and not larger than max date -1 month
if(num(weekday(Max(Date))) <= 6 and
num(weekday(AddMonth(Max(Date),-1))) <= num(weekday(Max({$}Updated))), 1,0)