SSAS compare 2 YTD values for same month in different years - excel

I am developing a cube in SSAS, I need to be able to compare YTD values between current year and last year.
I have the below scenario:
Budget types by year : budget1-2016 , budget2-2016 ,budget1-2017
, budget2-2017.
The budget types should be placed in the columns
Units: should be placed in the rows
The measure is called "Billings"
I need to compare YTD value for "Billings" between budgets "budget1 - 2016" and "budget2-2017" (different budget types and year) for a specific month.
when the Calendar month is included in the rows or columns everything works fine,
but if it is included in the filter and I choose for example February 2016 and February 2017, the results are not as expected.
With the usage of the TAIL function, only the higher month is taken into consideration and the column from 2016 is removed.
Is there a way to put the calendar month in the filter, select same month from different years and be able to see their YTD values?

The problem is that you put two members in the filter. CurrentMember doesn't work with two tuples. Hence [Data Date].[Calendar].CurrentMember is [Data Date].[Calendar].DefaultMember is [Data Date].[Calendar].[All]. It runs the following code:
Sum(
PeriodsToDate(
[Data Date].[Calendar].[Calendar Year],
[Data Date].[Calendar].[All]
),
[Measures].[_Billings]
)
You are choosing two month from different year, thus it's unclear what do you want to return from the PeriodsToDate() function. The data since January 2016 or January 2017? Choosing one of the members will fix your problem and make it clear.
I don't guarantee that's the perfect code to work with, but it may does the magic as well, add yet another calculated members to sum months:
Sum(
existing [Data Date].[Month].[Month].Members,
[Measures].[Billings]
)

Related

Excel: Count distinct numerical values if string condition matches

I have a list of employee names on one tab and another tab with orders shipped by employees and the month they were shipped going back 12 months. I'd like to calculate the average number of products shipped per employee per month, but I need to know how many months they were here to do that. So what I'd like to do is essentially write a formula that says give me the count of the distinct number of months they've been shipping products.
Sample employee data:
And here's the sample data on the individual shipments:
So in short, I need to know that Joe Smith shipped those 250 products across 3 distinct months to see he averages 83.3 shipments per month. Again, because there are many new people who have come onboard in the last 12 months, I can't just divide them all by 12 and need to know how many months they were shipping items in.
FILTER Shipper and Month based on Shipper column with criteria Employee name. Apply UNIQUE on filtered array to get only unique values (name + month number). Use COUNT to get active months. Divide Products Shipped by it.
Result:
Average by Count of Uniques
=LET(Shippers,B2:B11,Months,C2:C11,uShippers,E2:E4,uProducts,F2:F4,
uMonths,BYROW(uShippers,LAMBDA(uShipper,
ROWS(UNIQUE(FILTER(Months,Shippers=uShipper))))),
IFERROR(uProducts/uMonths,""))
You can use this array version, which spills all the results at once:
=LET(empl, A2:A4, prods, B2:B4, shipper, B7:B16, months, C7:C16,
ux, MAP(empl, LAMBDA(e, COUNT(UNIQUE(FILTER(months, shipper=e))))), prods/ux)
Here is the output:
It is also possible not using MAP but it is a verbose solution:
=LET(empl, A2:A4, prods, B2:B4, shipper, B7:B16, months, C7:C16,
left, TRANSPOSE(N(shipper=TOROW(empl))), right, N(months=TOROW(UNIQUE(months))),
cnts, N(MMULT(left, right)>0), ux, MMULT(cnts, SEQUENCE(ROWS(cnts),,1,0)), prods/ux)
Replacing TOROW with TRANSPOSE it should work for older Excel versions.
This is how I would have done it, create a Pivot table(Insert->Pivot Table) with Months as column, Employee as row and the values as count of shipments. Once you have the Pivot table, your life becomes easier. Now you do a count of the employee row (COUNT(COL-1:COL-X)) to count the total months a particular employee showed up.You now have count of shipments and a count of months. You can calculate the average. Not sure I can think of anything else easier.

Getting workdays for the year in Power Pivot DAX

I need to use the full year's work days in my DAX calculation, but I can't figure out how to get DAX to do that. I have two tables,
1) sales with their respective dates
2) work days table, with end of month and the month's respective work days
I created the relationship between the two, based on the date, and it works, however DAX captures workdays only for the month's where there were sales. How do I get the full year's sum?
As an example, these are the two tables I created:
and connected them as follows:
I then added a calculated field with the following DAX:
=CALCULATE(
SUM(tWorkdays[Days]),
FILTER(
tSales,
YEAR(tSales[Date]) = YEAR(MAX(tSales[Date]))
)
)
and built a pivot table like so:
As you can see, it just captures workdays for the months where there were sales, but I need the entire total, regardless if there were any sales or not.
What can I do to fix this?
I'm not positive about the details, but it has something to do with ALL(), EXCEPT(), and VALUES()
A matter of context, as they say in DAX
https://powerpivotpro.com/2011/06/precedence-part-3-allexcept-vs-all-w-values/
And another explanation:
https://www.sqlbi.com/articles/using-allexcept-versus-all-and-values/

Calculate average based on a value column (count) in a pivot table

I'm looking a way to add an extra column in a pivot table that that averages the sum of the count for the months ("Count of records" column) within a time period that is selected (currently 2016 - one month, 2017 - full year, 2018 - 5 month). Every month would have the same number based on the year average, needs to be dynamically changing when selecting different period: full year or for example 4 months. I need the column within the pivot table, so it could be used for a future pivot chart.
I can't simply use average as all my records appear only once and I use Count to aggregate those numbers ("Count of records" column).
My current data looks like this:
The final result should look like this:
I assume that it somehow can be done with the help of "calculated filed" option but I couldn't make it work now.
Greatly appreciate any help!
Using the DataModel (built in to Excel 2013 and later) you can write really cool formulas inside PivotTables called Measures that can do this kind of thing. Take the example below:
As you can see, the Cust Count & Average field gives a count of transactions by month but also gives the average of those monthly readings for the subtotal lines (i.e. the 2017 Total and 2018 Total lines) using the below DAX formula:
=AVERAGEX(SUMMARIZE(Table1,[Customer (Month)],"x",COUNTA(Table1[Customer])),[x])
That just says "Summarize this table by count of the customer field by month, call the resulting summarization field 'x', and then give me the average of that field x".
Because DAX measures are executed within the context of the PivotTable, you get the count that you want for months, and you get the average that you want for the yearly subtotals.
Hard to explain, but demonstrates that DAX can certainly do this for you.
See my answer at the following link for an example of how to add data to the DataModel and how to subsequently write measures:
Using the Excel SMALL function with filtering criteria AND ignoring zeros
I also recommend grabbing yourself a book called Supercharge Excel when you learn to write DAX by Matt Allington, and perhaps even taking his awesome online course, because it covers this kind of thing very well, and will save you significant head-scratching compared to going it alone.

DAX year over year comparison

In a report that I am making in DAX I would like to have year over year comparison of a measure defined as:
Sales Count := CALCULATE(COUNT(fData[PN]);fData[Proc.Type]="CU")
This measure basically counts the amount of sales that were generated. I have a dataset that spans from the beginning of 2014 up to today (16/01/2018). My calendar table consists of a date column, a year column and a month column and is ranges from 01/01/2014 up to 31/12/2018 (to avoid contiguous date errors when using time intelligence functions).
I have defined a measure called PY Sales count as:
PY Sales Count := CALCULATE([Sales Count];SAMEPERIODLASTYEAR(dCalendar[Dates]))
This measure does the job I want it to do, aside from one issue. When comparing the month of january of this year to the month of January to last year, it appears that we are doing terrible. This is because the SAMEPERIODLASTYEAR function considers the FULL month of January for the year 2017 and compares it to the period from the first of January until the 16th of January (today).
I think I should thus try to build a custom measure to 'filter' the date table such that when the year over year measure considers the running month, it only takes the same period as the one on which sales were recorded to compare against, not the full period...
However, due to my sparse DAX experience, I cannot seem to get this right...
If anyone could help/assist me on this, that would be hugely appreciated!
Thanks in advance
I haven't had a chance to test this, but try something along these lines:
PY Sales Count := CALCULATE([Sales Count];
FILTER(dCalendar;
dCalendar[Dates] <= DATEADD(TODAY(), -1, year);
SAMEPERIODLASTYEAR(dCalendar[Dates])))

grouping in an excel pivot table with different year end and quartiles

I have a pivot table with a lot of items currently grouped by date into quartiles and then months under that. My question is this, Our Financial year is not Jan to Jan so can I set up quartiles to reflect this? also our financial periods are not simply set months, they follow the months but are always full weeks around that. for example, P1 this year is 04/07/2015 - 07/08/2015. and Q1 would be 04/07/2015 - 02/09/2015.
Aside from manually grouping is there a way to set this up to happen automatically within Excel?
As stated by pnuts in the question's comments:
The most practical way may be to define the quarters (?) in your source data.
If you are at least using a Gregorian calendar, you may want to subtract an offset from your dates (i.e. # of days between 01-Jan-YYYY and DD-MMM-YYYY ... whereby the offset YYYY doesn't need to be the same as your date's YYYY). By this subtraction you get an "ordinal number" of the date within your business year.
[offset] =[FOY]-DATE(YEAR([FOY]),1,1)
So with your year starting on [FOY]=04-Jul-2015, you have an offset of of 184 days and a normalized date of
[date_normalized] = [current_date]-[offset]
So 04-Jul-2015 will be shrunk to 01-Jan-2015. Now the quarter easily calculates to
=CEILING(MONTH([date_normalized])/3,1)
... or =VALUE(MID("111222333444",MONTH([date_normalized]),1)) ... if you prefer
For your not-quite-months always being full weeks, I suggest to calculate a week number by
=MOD(CEILING(([date_normalized]+1)/7,1)-1,52)+1
to create a weekly reporting period 1 .. 52. With a further =CEILING(.../4,1) this can be converted to quasi-months having 4 weeks each.

Resources