SSAS Calculated member that knows if the user is using the report filter - excel

I am trying to write a calculated member which acts differently depending on whether the user is filtering by that member or has it dragged down as rows or columns on their pivot table (using Excel).
The rules are:
1. If the user is using the date dimensin as a Report Filter in Excel, then the calculated member should get the maximum date out of all dates that they are filtered by.
2. If they have the date dimension as rows on the pivot table, then I need to apply ClosingPeriod and some other logic.

Please try this. The idea came from here.
Basically the dynamic named set represents what's in the report filters. And the EXISTING keyword trims the list of days down to the filter context of the current cell letting you detect say if one month is on rows. Compare counts and you can detect what the user did.
CREATE HIDDEN DYNAMIC SET CURRENTCUBE.SelectedDays as
[Date].[Date].[Date].Members;
CREATE MEMBER CURRENTCUBE.[Measures].[My Calc] as
CASE
WHEN SelectedDays.Count > {existing [Date].[Date].[Date].Members}.Count
THEN Tail({existing [Date].[Date].[Date].Members},1).Item(0).Item(0).Name
WHEN SelectedDays.Count < [Date].[Date].[Date].Members.Count
THEN Tail(SelectedDays,1).Item(0).Item(0).Name
END
Performance is going to not be good. And I suspect users will be confused with the results of your calc. If you want to describe the business scenario more I can maybe recommend a better approach.

Related

Excel Pivot Table - Uneven group interval

I have around about 12,000 individual accounts with balances ranging from .01 to over 5mm. I want to group them in a column header so that I know the number of accounts that fall into each range as well as the summed up value of those accounts. I know how to create my pivot table to do this except for the grouping. I can only get one group to work (0-100,000 and >100,000). What I need is:
0-100,000; 100,000-1,000,000; 1,000,000-5,000,000; 5,000,000+
Can this be done? Manually grouping them isn't very viable given that I have 12,000 different account balances....and I wouldn't really want to do that manually anyway.
Can you add a calculated column to the source of the data with a formula to return the categories you want? A nested "If" statement should handle it with ease. Something along the line of:
=IF(AND(BALANCE>0,BALANCE<100000),"0-100,0000",IF(AND(BALANCE>=100000,BALANCE<1000000),"100,000-1,000,000"))
Just add in the rest of the IF(AND(X,Y),"Display text") to generate your categories.
You could skip the Pivot table entirely and use COUNTIFS
=COUNTIFS(A$1:A$10,">"&0,A$1:A$8,"<="&100000)
=COUNTIFS(A$1:A$10,">"&100000,A$1:A$10,"<="&500000)
And so on
For the last category you can use a COUNTIF
=COUNTIF(A$1:A$10,">"&5000000)
(My formulas assume the data is in Range A1:A10)

Index Match SumIF Problems

I'm trying to create a formula that sums student attendance by week, based on the students ID number. Basically, I want it to look up the student ID, and then output the sum of attendance for certain weeks. This is what I came up with, but it's not working correctly. I'll also need this for each month.
=sumifs(index(Attendance!$A:$Z,MATCH('Attendance by Week'!A5,Attendance!$A:$A,0),0), Attendance!$F$6:$Z$6,Attendance!$F$4:$Z$4,">=" &'Attendance by Week'!F$4,Attendance!$F$4:$Z$4,"<"&'Attendance by Week'!F$4+7)
Attendance by Week Worksheet:
The dates are the start of the week (every Sunday)
Attendance Worksheet:
Each "1" means the student was present
Any Help is appreciated!
For this type of challenge I would skip formulas completely, and go with a PivotTable-based solution because not only do they aggregate things without the need for complex formulas but they also let you group things by numbers of days.
The only barrier you have is that your data is currently as a crosstab, and PivotTables don't like 'em. So you'd need to either change the data entry layout to a flat file i.e. this:
...or use one of the methods I outline at convert cross table to list to make pivot table to turn your crosstab into a flat file. (I used PowerQuery, which is built in to Excel 2016 or later and available as a free addin for Excel 2010 or 2013).
But once you've done that, you can then create a PivotTable that automatically does all that grouping and summing, like so:
...using the Grouping feature:

Excel: Create lookup based on list of criteria

I have a little bit of an Excel problem and would be happy about any suggestions.
Long version: I have a dataset with raw data representing journal entries. The structure of this dataset can be seen here:
Now, what I want to achieve is to assign each row/each journal entry to a cost category (marketing, personnel, IT, depreciation, …) based on the values in the account number, type, and cost center rows, and, in a second step, break down the categories once more, eg. for labour costs, distinguish between direct and indirect labour costs.
The way my company does this right now is using an Excel sheet with several macros where the criteria are hardcoded in the VBA code to loop through the whole list, check if a row matches the criteria for a certain cost category, and if it does, copy the row to a new sheet (having one new sheet for each category), then using a second macro to break down the categories, assigning values to the “description”-column which is empty initially based on another set of criteria. Then, pivot tables are used on each of the new sub-datasets to calculate sums for each sub-category. These sums are finally used as input data for a management report (as seen in the image above) which is the ultimate goal of this whole ordeal.
Now, not only does this seem overly complicated to me and running the macros and manually adjusting the input ranges for the pivot tables takes forever, but also the criteria for allocating the costs can change quite often, and opening the VBA editor and changing the code is not really user-friendly.The initial idea was to maybe include some helper columns (one for each cost category) and somehow create an indicator variable being one of the entry falls in the respective category, and zero otherwise, and then use these columns for further calculations (e.g. for Sumifs and such).
The problem is that a) combinations of account number and type are not unique, so that one account number can go along with various types, and one type can go along with various account numbers, so the criteria can be something like C6 = 544300 OR 544700 AND D6<>110246, etc. And b) criteria can change, meaning sometimes a new account number or type is added that also has to be assigned to an already existing category such as labor costs, which would make it necessary to include that criterion in all the formulas for that particular cost category. So, is it possible to somehow create a criteria table for each category that serves as input for some sort of IF/SUMIF or lookup function?
Short version: I have a data set (can range from 5000 to up to 100000 rows, 8 columns) where I want to perform a lookup, but based on various criteria. And, in addition to that, it would be nice if the criteria could somehow be drawn from a separate list so that they can be modified fairly easily without having to change the formula itself. Is there a way to do so? Or do you think using the advanced filter might be the most suitable option?

Dax code: find sum of values filtered by month

I have seen some posts that address this concept online, but I have been unable to adapt them to my needs.
Scenario:
I have a table with three columns.
Column A- [Month] (formatted mm/dd/yyyy)
Column B- [salesperson]
Column C- [Assets]
I am trying to determine a formula which will return the total assets for all salespeople for each month in a fourth column.
Why am I doing this? I am building a report which will generate a graph from this data. In reality there will be additional columns which will contain values for some variables. I will be using the slicer function in conjunction with these variables to create an interactive functionality within the graph. Hard coded references won't work for me, as this will be a recurring report, and the dataset will be refreshed with current data regularly.
Thank you for any help you can offer. I'm still fairly new to all this (<1yr) so interpreting general formulas I've found elsewhere has been very problematic.
Cheers!
Create a calculation like this (syntax dependent on data model)
AllSalespersons:=CALCULATE(SUM[Assets], ALL[Salesperson])
Using the CALCULATE function here is important because it will remove the row syntax for Salesperson (created in the pivottable) and give you the sum of 'ALL' salespersons for each month.
Again, you'll have to play with the syntax to fit your data model, but based on your quetsion, I think this should give you what you are looking for.

How do I create report-like data tables in Excel?

In the past I have created websites that extract data from a database and format it using tables.
Now, I am trying to do the same thing but with Excel, and I'm lost. I am used to using SQL commands to extract data from given fields and then sort/manipulate it.
Currently, I am able to print a report that provides me with an Excel spreadsheet full of raw data, but I would like to make my life easier and organize it into a report.
The column that I would like to reference contains duplicates, but the data in the adjacent columns is different.
To give an example, assume I had a spreadsheet of sales transactions. One column would be the Customer ID, and the adjacent columns would contain the quantity, the cost per unit, total cost, order ID, etc.
What I would want to do in this case would be to select all the transactions with the same Customer ID and add them together based on their Order ID. Then, I would want to print the result to a second sheet.
I realize that I can use built-in functions to accomplish this, but I would also like to format this report evenually using VBA. Also, since I will have a variable number of rows that differ from one report to the next, I haven't encountered a fucnction that will allow you to add rows.
I'm assuming this must be done with VBA.
Well you can do it manually, but it would take ages. So VBA would be good, particularly as you would be able to generate future reports quickly.
My interpretation of what your saying is that each row in your report will be the total for one customer ID. If it's something else, I imagine the below will still be mostly relevant.
I think it would be a bit much to give you the full answer, particularly as you haven't provided full detail but to take a stab at what you'd do:
Create your empty report page, whether it be a new worksheet or a new workbook
Loop through the table (probably using While next is not empty)
a. Identifying if a row is for a customer ID you haven't covered yet
i. If so then add a new entry in your report
ii. Else add it to the existing customer ID record (loop through until you find it)
Format your report so it looks pretty, e.g:
a. Fill the background in white
b. Throw in some filled bars
c. Put in good titles and totals etc.
For part 1, it might be better building an array first and then dumping the contents into the report. It depends how process intensive it will be - if very intense, an array should shave off time.

Resources