I am writing LYQTD and LYYTD measures mdx query for show previous year data on the basis of current selected date filter these mdx working quite fine but i am not able to aggregate Last Year to date and Last Quarter to date data.
for ex:- I want to filter data for LYQTD and LYYTD.
these are some sales sample data for different months:
Jan 1000
Feb 5000
Mar 1000 Quarter1
apr 2000
May 4000
Jun 6000 Quarter2
Jly 8000
Aug 6000
Sep 4500 Quarter3
Oct 6500
Nov 9000
Dec 2000 Quarter4
Now i want to aggregate these data on the basis of selected filter
for example i am select Jan month
LYQTD LYYTD
1000 1000
Now i am selecting Feb month the measures will be aggregated with the previous select filter
LYQTD LYYTD
6000 6000
Now i am selecting Quarter2 month apr the data will be shows as
LYQTD LYYTD
2000 8000
My applied queries as mentioned below if there is any solution please help me.
CREATE MEMBER CURRENTCUBE.[Measures].ActualsLYQTD
AS
AGGREGATE(PARALLELPERIOD([Time].[Time].[Quarter],4,[Time].[Time].CURRENTMEMBER),
[Measures].[Revenue and Expenses]),
VISIBLE = 1 , ASSOCIATED_MEASURE_GROUP = 'Actuals' ;
CREATE MEMBER CURRENTCUBE.[Measures].ActualsLYYTD
AS
AGGREGATE(PARALLELPERIOD([Time].[Time].[Year],1,[Time].[Time].CURRENTMEMBER),
[Measures].[Revenue and Expenses]),
VISIBLE = 1 , ASSOCIATED_MEASURE_GROUP = 'Ac``tuals' ;
You have to use ParallelPeriod() to get the same member a year before, PeriodToDate() to get a set from the beginning of the year until current member, Aggregate() to get aggregated value of [Measures].[Revenue and Expenses] against the set.
Aggregate(
PeriodToDate(
[Time].[Time].[Year],
ParallelPeriod(
[Time].[Time].[Year],
1,
[Time].[Time].CurrentMember
),
),
[Measures].[Revenue and Expenses]
)
Related
I have the following table
image of database in use
i want to get the following kind of results
jan 12500
feb 16500
mar 4500
apr 6500
the query should return a total for each month for desired months.
i know how to do this..
$sql = "SELECT SUM(cost) as january FROM earnings WHERE month= 1 and year= '$2022" ;
to get the sum for a given month but I cant find anything on how to get multiple months at once.
am still new to this
SELECT
SUM(cost) as cost,
month
FROM earnings
WHERE year = :year
GROUP BY month
Sum all entries of cost, per month (GROUP BY) found in year (:year)
Each ROW will have a column cost and month.
If you want to "further" filter the months you can apply another AND clause
AND (month >= 1 OR month <= 6) for January to June
Useful Source:
https://www.mysqltutorial.org/mysql-group-by.aspx
I have an OLAP multi dimensional cube, which in its simplest form contains:
A fact table with a NetAmount measure
A Time dimension, with fields for Year, Month, Day, Day of Month, Day of Year, etc
The requirement is that the user wants to be able to compare the total NetAmount from the beginning of each year up to a specific date. The date can be chosen by setting filters on the Day and Month fields. For example, the user wants to see total value for:
01 Jan 2019 to 20 Jan 2019
01 Jan 2018 to 20 Jan 2018
01 Jan 2017 to 20 Jan 2017
etc
What would be the best way to tackle this requirement?
You can create calculated member with YTD function like this:
CREATE MEMBER CURRENTCUBE.[Measures].[NetAmountYTD]
as
Aggregate(YTD ([Time].[Time].CurrentMember), [Measures].[NetAmount])
You could also create Utility dimension for example TimeUtility, and add YTD member, and define it like this:
Scope([TimeUtility].[YTD]);
this = Aggregate(YTD ([Time].[Time].CurrentMember), [TimeUtility].[DefaultMember]);
End Scope;
This way whatever measure you look against [TimeUtility].[YTD] it will give you Year to Date for that measure, not just NetAmount, so it will be general solution.
I am attempting to graph, via Power View, the sum of all account balances at various points in time, so that I can see how the total is changing.
I do not have transaction history (add / subtract), only 'Balance' at a specific point in time for each account.
A simplified example of my data is:
Account Date Balance
a111 01 January 2015 100
a111 01 February 2015 150
b222 01 March 2015 200
c333 01 March 2015 300
b222 01 May 2015 150
d444 01 June 2015 400
As far as I can tell, I need to create a measure to generate a dynamic rank per 'Account', ordered by latest date. I should then be able to create a second measure to SUM each account where the rank = 1.
There is a similar example of this issue discussed in the question PowerPivot DAX - Dynamic Ranking Per Group (Min Per Group), however I cannot seem to get this to display how I want on a line graph in Power View.
What I want to display on the line graph is (letting the graph sort out the missing dates):
Date Balance
01 Jan 2015 100 -- Account a111 only
01 Feb 2015 150 -- Account a111 only, but the new value
01 Mar 2015 650 -- Accounts a111 (latest), b222 and c333
01 May 2015 600 -- As above, but account b222 is updated
01 Jun 2015 1000 -- Latest values for all accounts
However, what I am currently seeing is:
Date Balance
01 Jan 2015 100 -- Sum of Balances matching this date
01 Feb 2015 150 -- As above
01 Mar 2015 500 -- As above
01 May 2015 150 -- As above
01 Jun 2015 400 -- As above
The problem, as far as I can tell, is that at each data point in the graph, the 'filter context' is reducing down to only the rows that match the date, whereas I need all rows on on before that date with a 'rank' of 1.
For reference, I am using Excel 2013 and the data is ultimately coming in via Power Query (pulling data from SharePoint), so I can work some magic there if necessary (i.e. generating a numeric 'group id' for use with DAX MAX() function, as that doesn't seem to like strings).
I hope this is not to confusing, and thanks in advance for any help.
The solution to this is to have a separate date dimension table so balance can be independently calculated on a per-month basis without respect to the fact table.
Let's assume you have a date table called Date.
So, first create the base measure
[Total Balance] := SUM( FactTable[Balance] )
Next we calculate the first month in the fact table to use as a floor for looking through our Date table values.
[First Ever Balance Date] := FIRSTDATE( ALL( FactTable[Date] ) )
And now we determine the last date with a balance for the date range between that first month and the current month in context:
[Last Balance Date] :=
LASTNONBLANK (
DATESBETWEEN ( Date[Date], [First Ever Balance Date], MAX ( Date[Month] ) ),
[Total Balance]
)
So take account a111 in the month of 5/1/2015. This measure will look in all the dates between 1/1/2015 (our [First Ever Balance Date] ) and 5/1/2015 ( the MAX Date[Month] ) , find the last row with a balance and return the corresponding Date[Date] ( 2/1/2015 ).
This measure will return BLANK for any month before an account's initial balance. Using BLANKS in date filtering doesn't work, so we should replace these BLANK values with the [First Ever Balance Date] to ensure the running balance for that account will still return 0.
[Last Balance Date Remove Blanks] :=
IF (
ISBLANK ( [Last Balance Date] ),
[First Ever Balance Date],
[Last Balance Date]
)
Now we can calculate the current balance of any account for any month by looking up the balance as of the Last Balance Date Remove Blanks
[Last Balance] :=
CALCULATE (
[Total Balance],
DATESBETWEEN ( Date[Date], [Last Balance Date Remove Blanks],
[Last Balance Date Remove Blanks] )
)
And finally we use a SUMX across the accounts to add up their individual Last Balance amounts.
[Account Total Balance] := SUMX( ALL( FactTable[Account] ), [Last Balance] )
Now in your pivot table you just put Date[Month] on the rows and [Account Total Balance] as the measure. Note this will include months with no fact table rows like 4/1/2015 in your sample set. If you wish to exclude these, add another intermediate measure to count your fact table rows:
[Fact Table Row Count] := COUNTROWS ( FactTable )
And then create a measure to return BLANK() if [Fact Table Row Count] is BLANK(), and otherwise [Account Total Balance]
[Account Balance Hide Rows] :=
IF (
ISBLANK ( [Fact Table Row Count] ),
BLANK (),
[Account Balance]
)
I would like to get a running tally of how many widgets were/are rented at any one time, by month, by year. Data is held in an MS Access 2003 db;
Table name: rent_table
Fields:
rentid
startdate
enddate
rentfee
rentcost
bookingfee
Something like; Count number of rentid's that fall between month/year, then group them?
e.g. if a widget was rented from 5th Jan 2014 to 8th April 2014 it would appear as a count in Jan, Feb, Mar and April tally's.
Many thanks.
EDIT
More details (sorry);
Access db is fronted by classic ASP.
If possible I don't want to create any new tables.
No input is required in order to run the report.
There are around 350-400 widgets that could be rented at any one time.
Each widget is rented exclusively.
Report output example;
Month | Year | NumRented
Jan 2014 86
Feb 2014 113
...
Can a query pick up dates within dates? So literally do a count of the table where date >Dec 31st 2013 AND <1st Feb 2014 (to grab a count for all of January 2014) and would that include the example of the rent starting on the 5th Jan? So I could just do twelve counts for each year?
create a calendar table, e.g.
table = cal_yyyymm with one column dt_yyyymm as numeric field
populate the table with ... say 5 or 10 years of data
201401 201402 201403 ... 60 or 120 rows, a small table
make a sql
Select
dt_yyyymm,
count(*) as cnt
From cal_yyyymm
Left Join rent_table
On format(startdate,"yyyymm") >= dt_yyyymm
And dt_yyyymm >= format(enddate,"yyyymm")
think about the complications in the data -- --
widget was rented from 5th Jan 2014 to 8th Jan 2014
and again rented from 11th Jan 2014 to 21st Jan 2014
does this count at 1 or 2 in the month?
if it is 1, then the sql gets more complicated because
the rent_table first needs to have its dates converted
to yyyymm format, and second needs to be de-duped on rentid,
and third then joined to cal_ On the dates...
I have 2 lakhs of data in my database,need to fetch record based on 'uploaddatetime'
(Column in database)of every 15 days.For example,
Date Number of Records.
April 1st-15th 20
April 16th-30th 40
May 1st to 15th 1000
May 16th to 31st 4000
Till date,have any idea to fetch data using Microsoft SQL-2008 R2
You can do something like this
select
case
when date_col>='20130401' and date_col<'20130416' then 'April 1st-15th'
when date_col>='20130416' and date_col<'20130501' then 'April 16th-30th'
.
.
as date_range
end
count(*) as total
from table
group by
when date_col>='20130401' and date_col<'20130416' then 'April 1st-15th'
when date_col>='20130416' and date_col<'20130501' then 'April 16th-30th'
.
.
end