PowerPivot Group By to find a count of values - excel

I have a PowerPivot data model with thousands of rows and I'm trying to add a column that shows me the number of times a value occurs based on grouping the values in other columns. For example, I want to count the total number of times an item has shown $ greater than zero for a dept by for each combination of item and date. in the picture example provided here, 9 total stores show $ for the item for the specific date. I'm looking to do this in a column instead of a measure so I can merge it with other data. I have it solved as a measure with this formula:
CALCULATE (
SUMX (
ADDCOLUMNS (
SUMMARIZE (
Append1,
Append1[UPC],
Append1[Weeks]
),
"NumStoresSell", CALCULATE(
COUNT ( Append1[$] ),
Append1[$] <> 0
)
),
[NumStoresSell]
)
)
Any ideas on how I can solve it as a column?
thank you!

This DAX formula will return the number of rows in a table that matches all three criteria specified, row-by-row. The && means AND. You can swap this out with || for an OR criteria.
This example is a formula entered into a table named Summary and counts the rows in a table named Data with the columns for Item, Transaction Date and Transaction Amount having values matching the formula's row in the Summary Table.
= CALCULATE(
COUNTROWS(Data),
FILTER(Data,Data[Item]=Summary[Item],
&&Data[Transaction Date]=Summary[Transaction Date]
&&Data[Transaction Amount]=Summary[Transaction Amount]
)
)

Related

subtract two column pivot table using calculated value

I need to find the average of profit by subtracting ( average budget from average revenue ) , both these two column calculated by pivot table
I tried to input this in the calculated field: =AVERAGE('Box Office Revenue ($)')-AVERAGE('Budget ($)')
and then summarized field value to Average but still show summation.
i don't need to subtract the summation of these two column but i need to subtract the averages.
Can you please support in that.

Excel: Lookup Multiple values with duplicates in multiple columns

I'm trying to link multiple lists and show all the values. Including duplicates.
My worksheet has data in 11 Columns. One column with Products(which can appear multiple times) and the rest with Store(which sell the products, no store sells the same product).
A small example here:
I've made a helper column(A) using the following formula : =B2&COUNTIF($B$2:B2,B2) . The helper column counts how many time a product show up in the Products Column(B). I thought it was needed.
I've managed to sort the data a bit using =VLOOKUP($C$2&ROWS($L$1:L1),$A$2:$C$11,2,0) like this :
Result
But I want to sort the data in a single Column for each store like this:
Desired Result
, without having to change the formula every 2-3 rows, as some store have 30 or so products. Is this something achievable with either formulas or VBA?
I would like to have the results in one column :
List Store 1 items as many times as they appear in Product column.
If an item(from Store 1) doesn't show up in Product column show "Product name -"
Product Column can have repeatable items
Each store has different products, so there's no conflict there.
If possible, since i have they Helper Column, if a product shows up 4 times, when i drag the formula in the 5th row it should jump to the next product.
Hope this is clear enough. Thank you
Later Edit: Maybe this helps a bit in understanding what I want to obtain.
Column 1 helper I've added it to count how many times a product shows up in Column 2. I want to get a separate column, which shows the items in Column 3(store1) x how many times they appear in Products Column. In the example above Store1 has product "Hansa" which appears 4 times in Product Column so it should appear 4 times in the separate column, after it there's product "Korek" which appears 1 time in Product Column so it should appear one time in the separate column under "Hansa" and so on. So basically I want to compare the third column to the second and show to values in the third x times they appear in the second in a different column.
This formula uses F1 as a helper cell, which is needed to count the matches in the product list.
Enter this FormulaArray in F1:
=SUM( IF( ISERROR( MATCH( $B$2:$B$11, $C$2:$C$6, 0 ) ), 0, 1 ) )
Enter this formula in E2:E11:
= IFERROR( INDEX( $C$2:$C$6,
AGGREGATE( 15, 6,
MATCH( $B$2:$B$11, $C$2:$C$6, 0 ),
ROWS( E$2:E2 ) ) ),
IFERROR( INDEX( $C$2:$C$6,
AGGREGATE( 15, 6,
ROW(E:E) / ISERROR( MATCH( $C$2:$C$6, $B$2:$B$11, 0 ) ),
ROWS( E$2:E2 ) - $F$1 ) ) & "-", "" ) )
Note that the helper column A is not needed.

Lookup column with dates in PowerPivot

I need to add a column on a table, computed from another one but I can't get the formula right.
Here are the tables and columns:
Table 1
Date (date)
Table 2
Key (text)
Start (date)
End (date)
I want to add a column to the Table 1 which will contains the Key from Table 2 where the Date column is between Start and End from Table 2.
If the date cannot be found in a range, then the field should be blank.
Try creating a calculated column in Table1 called Key and use this expression:
=
CALCULATE (
LASTNONBLANK ( Table2[Key], 0 ),
FILTER ( Table2, Table1[Date] >= Table2[Start] && Table1[Date] <= Table2[End] )
)
I am assuming in your table2 there is no overlaps between dates and
every date in Table1 will match only one start-end range.
It is not tested but should work, let me know if this works for you.

Left outer join sum with DAX

I have 2 tables:
Fact sales table (sales)
Dimensional period table (dimperiod)
I have joined them through my model on the Period column. However, when I display the sales sum I got this.
I would like to have a row where no sales were made with a sum equal to 0. As below:
I've used the following DAX but didn't work.
CustomSales:=CALCULATE(SUM([Sales]), NATURALLEFTOUTERJOIN(sales,dimperiod))
Just change the pivot table to display blanks.
Or add 0 to your measure. Pivot tables do not display blanks by default. The first option above forces the pivot to display blanks, but you'd need to set this per pivot table. Addition implicitly coerces a blank to a numeric type.
SumSales:=
SUM( 'Sales'[Sales] ) + 0

Microsoft Access Query - Finding Data Based On Date

I have an excel table in which there are multiple date columns. Each date column has another column next to it that has the total number of items for that day. So, for example, the table has Date 1, then Number of Items 1, then Date 2 and Number of Items 2 and so on and so forth up until 10.
Example:
Date 1 --| Number of Items 1| Date 2-----| Number of Items 2
9/10/13 -| -------2---------| 9/11/13----|-------3---------
9/9/13 --| -------2---------| 9/10/13----|-------3---------
I need a way in Microsoft Access to design a query that can grab the total number of items for a specified date in each row. The issue is that the dates that are entered into each date column aren't going to be uniform, meaning that the first row entry for Date 1 and Date 2 might be 9/10/13 and 9/11/13 but the entry into the next row for Date 1 and Date 2 might be 9/09/13 and 9/10/13 respectively (see the example above).
The purpose of this is to be able to determine the total number of items people have entered into the table based on the date I specify. As you can see, this presents an issue because if I needed to find the number of items for 9/10/13, I would need to somehow pull in the data in the first row from the Number of Items 1 column and from row two in the Number of Items 2 column. Although the structure of the table isn't ideal for what I'm trying to accomplish, I have no control over its design.
Is this possible, and if so how can it be accomplished?
You can pull the first pair of columns in one SELECT query, then union that with a SELECT of the second pair, and so forth ...
SELECT [Date 1] As the_date, [Number of Items 1] AS number_of_items
FROM YourTable
UNION ALL
SELECT [Date 2] As the_date, [Number of Items 2] AS number_of_items
FROM YourTable
You can later use that big union query as the input for another where you do a GROUP BY date and sum the number of items for each date.

Resources