Dax code: find sum of values filtered by month - excel

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.

Related

Excel sheets with scores by same ID of person (Kahoot) - How to extract and summarize scores from several quizzes?

I've used Kahoot in the classroom and have several excel files with scores from quizzes.
Students attended quizzes by using unique IDs. In each file, scores are visible for each ID (but ordered by success on each quiz). There are also some students missing or stating wrong IDs (I'll ignore it).
Now I would like to accumulate all scores for all student IDs in one sheet and summarize them by Student ID.
How can I do that most efficiently?
Any pointer or advice is appreciated.
Thanks,
B.
Here's a high level guide to getting what you want along with a sample in this file.
Step 1 - Combine Files to Sheet with Unified Columns
Objective
The goal here is to:
Combine all of your data from other files to single sheet
Merge the data to be in a single column for each field (i.e. Column A has ID, Column B has score).
No breaks in rows.
No formulas.
To illustrate, I made this fake list based loosely on your
description.
Method
You probably can do this manually, but a macro could also be used. If you expect to do this year over year, you might look into vba to open close files in a folder. However, since that wasn't part of question, you can do copy-paste (better yet make a kid do it!). Just make sure there's only one header for each column, and all of the data records align. Probably should do copy paste value if you have any formulas.
Step 2 - Show Summation
There's a couple ways this could be done. A pivot table is probably the most sensible because you could include each quiz as a column to see the total. You could also use a pivot table to do averages by student etc.
TO make a pivot table, I would recommend going on YouTube and they will do a better job of explaining than me.
On that same file I made as an example, I included some tabs to illustrate the power of pivot tables and a couple graphs.
Hope that helps. If you have specific technical questions on this, you might consider asking separately.

Criteria of SUMIF Function referring to data previously in table

Is there a way to add values in Excel based off of values previously in table?
For example, in the table I currently have, is there a way to exclude adding the 1 from the "Attended" column in the "Sonics and Cold Cash" row because I already had a row with "Sonics" and "1" in attended? I don't want to add a 1 to the SUMIF function if I have already attended that team once before.
I hope this is clear enough for some help. Thank you!
edit: So far, I have a table that tracks how many times a team has been "attended". This works, however I am trying to use linear optimization for scheduling, and using the results table has some linearity problems. I'm trying to find a way to only use the table instead of a second, results table.

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?

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

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.

Resources