Unique count of values in column per month - excel

Excel-Table:
| A | B | C | D | E | F | G |
-----|----------------|-----------------|------------------|--------|---------|---------|---------|-----
1 | month&year | date | customer | | 2020-01 | 2020-03 | 2020-04 |
-----|----------------|-----------------|------------------|--------|---------|---------|---------|-----
2 | 2020-01 | 2020-01-10 | Customer A | | 3 | 2 | 4 |
3 | 2020-01 | 2020-01-14 | Customer A | | | | |
4 | 2020-01 | 2020-01-17 | Customer B | | | | |
5 | 2020-01 | 2020-01-19 | Customer B | | | | |
6 | 2020-01 | 2020-01-23 | Customer C | | | | |
7 | 2020-01 | 2020-01-23 | Customer B | | | | |
-----|----------------|-----------------|---------------- -|--------|---------|---------|---------|-----
8 | 2020-03 | 2020-03-18 | Customer E | | | | |
9 | 2020-03 | 2020-03-19 | Customer A | | | | |
-----|----------------|-----------------|------------------|--------|---------|---------|---------|-----
10 | 2020-04 | 2020-04-04 | Customer B | | | | |
11 | 2020-04 | 2020-04-07 | Customer C | | | | |
12 | 2020-04 | 2020-04-07 | Customer A | | | | |
13 | 2020-04 | 2020-04-07 | Customer E | | | | |
14 | 2020-04 | 2020-04-08 | Customer A | | | | |
15 | 2020-04 | 2020-04-12 | Customer A | | | | |
16 | 2020-04 | 2020-04-15 | Customer B | | | | |
17 | |
In my Excel file I want to calculate the unique count of cutomers per month as you can see in Cell E2:G2.
I already inserted Column A as a helper column which extracts only the month and the year from the date in Column B.
Therefore, the date-formatting is the same as in the timline in Cell E1:G2.
I guess the formula to get the unique count per month is somehow related to =COUNTIFS($A:$A,E$1) but I have no clue how to modify this formula to get the expected values.
Do you have any idea?

Here's one approach which would work for Office 365 and if you have access to UNIQUE:
=COUNTA(UNIQUE(IF($A$2:$A$16=G$1,$C$2:$C$16,""),,FALSE))-1
For older versions, following will work with CTRL+SHIFT+ENTER (array entry)
=SUM(--(FREQUENCY(IFERROR(MATCH($A$2:$A$16&$C$2:$C$16,E$1&$C$2:$C$16,0),"a"),MATCH($A$2:$A$16&$C$2:$C$16,E$1&$C$2:$C$16,0))>0))

You can do it without any helping column.
=SUM(--(UNIQUE(FILTER($C$2:$C$16,TEXT($B$2:$B$16,"yyyy-mm")=E$1))<>""))
For older version of excel use below formula with your helper column.
=SUMPRODUCT(--($A$2:$A$16=D$1)*(1/COUNTIFS($A$2:$A$16,$A$2:$A$16,$C$2:$C$16,$C$2:$C$16)))

Related

Calculate maturity of an annuity-loan with one formula in a cell without helper table

Excel
| A | B | C | D | E | F | G | H |
---|-----------------|----------|--------|--------|-----------|-------------|---------|----------|---
1 | Loan | 50.000 | Year | Start | Interests | Repayment | Annuity | End |
2 | Interests p.a. | 2% | 1 | 50.000 | -1.250 | -1.750 | -3.000 | 48.250 |
3 | Annuity p.a. | 3.000 | 2 | 48.250 | -1.206 | -1.794 | -3.000 | 46.456 |
4 | Maturity | ?? | 3 | 46.456 | -1.161 | -1.839 | -3.000 | 44.618 |
5 | | | 4 | 44.618 | -1.115 | -1.885 | -3.000 | 42.733 |
| | | | | | | | |
| | | | | | | | |
21 | | | 20 | 8.094 | -202 | -2.798 | -3.000 | 5.297 |
22 | | | 21 | 5.297 | -132 | -2.868 | -3.000 | 2.429 |
23 | | | 22 | 2.429 | -61 | -2.939 | -3.000 | 0 |
The above loan of 50.000 has an interest rate of 2% and an annuity of 3.000.
In the table from C1:H23 the annual development of the remaining loan is displayed.
Based on this helper table I know that the maturity of the loan is 22 years by using the following formula in Cell B4:
B4 = COUNTA(C1:C22)
However, my question is if there is an Excel-Formula that can calculate the maturity in one cell so I do not need the helper table in C1:H23?

Create descending list inlcuding duplicates based on filter criteria

Excel-File
| A | B | C | D | E | F |
---|--------------|-------------------|--------|-----------------|------------|------------|-
1 | Sales | Product | | Product | Sales | |
2 | 20 | Product_A | | Product_D | 100 | Product_D |
3 | 10 | Product_A | | Product_D | 90 | |
4 | 50 | Product_A | | Product_D | 50 | |
5 | 80 | Product_B | | Product_D | 50 | |
6 | 40 | Product_C | | | | |
7 | 30 | Product_C | | | | |
8 | 100 | Product_D | | | | |
9 | 90 | Product_D | | | | |
10 | 50 | Product_D | | | | |
11 | 50 | Product_D | | | | |
12 | | | | | | |
In Column B I have list of different products with their corresponding sales in Column A.
Products can appear mutliple times in the list.
Sales numbers can be equal for multiple products.
I want to use the value in Cell F2 as Filter-Criteria to create a descending list of the products in Column D and Column E sorted by the sales in Column A.
Therefore, I tried to add the FILTER function to the formula from this question:
=INDEX(SORT(FILTER(A2:B11,A2:A11=F2,""),2,-1),SEQUENCE(COUNT(A2:A11)),{2,1})
However, with this formula I get error #VALUE.
How do I need to modify the formula to make it work?
Simply add COUNTIF() inside the SEQUENCE():
=INDEX(SORT(FILTER(A2:B11,B2:B11=F2,""),2,-1),SEQUENCE(COUNTIF(B2:B11,F2)),{2,1})
Current view on OP side:
Due to unknown reason only Column D gets filled.

Show text as value Power Pivot using DAX formula

Is there a way by using a DAX measure to create the column which contain text values instead of the numeric sum/count that it will automatically give?
In the example below the first name will appear as a value (in the first table) instead of their name as in the second.
Data table:
+----+------------+------------+---------------+-------+-------+
| id | first_name | last_name | currency | Sales | Stock |
+----+------------+------------+---------------+-------+-------+
| 1 | Giovanna | Christon | Peso | 10 | 12 |
| 2 | Roderich | MacMorland | Peso | 8 | 10 |
| 3 | Bond | Arkcoll | Yuan Renminbi | 4 | 6 |
| 1 | Giovanna | Christon | Peso | 11 | 13 |
| 2 | Roderich | MacMorland | Peso | 9 | 11 |
| 3 | Bond | Arkcoll | Yuan Renminbi | 5 | 7 |
| 1 | Giovanna | Christon | Peso | 15 | 17 |
| 2 | Roderich | MacMorland | Peso | 10 | 12 |
| 3 | Bond | Arkcoll | Yuan Renminbi | 6 | 8 |
| 1 | Giovanna | Christon | Peso | 17 | 19 |
| 2 | Roderich | MacMorland | Peso | 11 | 13 |
| 3 | Bond | Arkcoll | Yuan Renminbi | 7 | 9 |
+----+------------+------------+---------------+-------+-------+
No DAX needed. You should put the first_name field on Rows and not on Values. Select Tabular View for the Report Layout. Like this:
After some search I found 4 ways.
measure 1 (will return blank if values differ):
=IF(COUNTROWS(VALUES(Table1[first_name])) > 1, BLANK(), VALUES(Table1[first_name]))
measure 2 (will return blank if values differ):
=CALCULATE(
VALUES(Table1[first_name]),
FILTER(Table1,
COUNTROWS(VALUES(Table1[first_name]))=1))
measure 3 (will show every single text value), thanks # Rory:
=CONCATENATEX(Table1,[first_name]," ")
For very large dataset this concatenate seems to work better:
=CALCULATE(CONCATENATEX(VALUES(Table1[first_name]),Table1[first_name]," "))
Results:

excel compare current time value from sheet1 to time value range from sheet2

I am trying to compare the time value from sheet 1 to sheet 2 and get the close match values in sheet1 -- B, C, D columns. Whenever I refresh the cell A it should automatically update the results in B, C, C, D see expected result
Sheet 1 show current time i.e., cell A1 "=now()"
Sheet1
----------------------------------------------------
| A | B | C | D |
|---------------------------------------------------
| 12:55:00 | | | |
----------------------------------------------------
In sheet 2, data available in 4 columns as below
--------------------------------------------------------
| No | Start | End | Date |
|-------------------------------------------------------
| 1 | 07:36:00 | 08:23:10 | 15/05/2015 |
| 2 | 08:23:10 | 09:10:20 | 15/05/2015 |
| 3 | 09:10:20 | 09:57:30 | 15/05/2015 |
| 4 | 09:57:30 | 10:44:40 | 15/05/2015 |
| 5 | 10:44:40 | 11:31:50 | 15/05/2015 |
| 6 | 11:31:50 | 12:19:00 | 15/05/2015 |
| 7 | 12:19:00 | 13:06:10 | 15/05/2015 |
| 8 | 13:06:10 | 13:53:20 | 15/05/2015 |
| 9 | 13:53:20 | 14:40:30 | 15/05/2015 |
| 10 | 14:40:30 | 15:27:40 | 15/05/2015 |
| 11 | 15:27:40 | 16:14:50 | 15/05/2015 |
| 12 | 16:14:50 | 17:02:00 | 15/05/2015 |
| 13 | 17:02:00 | 18:14:50 | 15/05/2015 |
| 14 | 18:14:50 | 19:27:40 | 15/05/2015 |
| 15 | 19:27:40 | 20:40:30 | 15/05/2015 |
| 16 | 20:40:30 | 21:53:20 | 15/05/2015 |
| 17 | 21:53:20 | 23:06:10 | 15/05/2015 |
| 18 | 23:06:10 | 00:19:00 | 16/05/2015 |
| 19 | 00:19:00 | 01:31:50 | 16/05/2015 |
| 20 | 01:31:50 | 02:44:40 | 16/05/2015 |
| 21 | 02:44:40 | 03:57:30 | 16/05/2015 |
| 22 | 03:57:30 | 05:10:20 | 16/05/2015 |
| 23 | 05:10:20 | 06:23:10 | 16/05/2015 |
| 24 | 06:23:10 | 07:36:00 | 16/05/2015 |
---------------------------------------------------------
Expected
Sheet1 - if the current time is 12:55:00 on 15/05/2015
-----------------------------------------------------------------------------
| A | B | C | D | E |
|-----------------------------------------------------------|---------------|
| 12:55:00 | 7 | 12:19:00 | 13:06:10 | 15/05/2015 |
-----------------------------------------------------------------------------
Sheet1 - if the current time is 03:55:00 on 16/05/2015
-----------------------------------------------------------------------------
| A | B | C | D | E |
|-----------------------------------------------------------|---------------|
| 12:55:00 | 21 | 02:44:40 | 03:57:30 | 16/05/2015 |
-----------------------------------------------------------------------------
for numbers I using the below formula but not sure how to achieve in case of time
=INDEX(A1:A20,MATCH(MIN(ABS(A1:A20-D1)),ABS(A1:A20-D1),0))
Thanks
If we assume that your dates are entered from different days but you want to treat them as though they are all on the same day, you just need to subtract off the days part before doing the comparison.
Since Excel stores dates as days with the decimal representing the hours/seconds, you can simply subtract off the integer part of the value.
Here is that formula. This is an array formula, entered with CTRL+SHIFT+ENTER.
=INDEX(A1:A20,MATCH(MIN(ABS(A1:A20-INT(A1:A20)-D1+INT(D1))),ABS(A1:A20-INT(A1:A20)-D1+INT(D1)),0))
For A1:A20 we subtract off INT(A1:A20). Same thing for D1 except D1 is already being subtracted, so the INT part gets added back in.
Thanks Byron, based on your solution, got an idea and implemented and achieved the desired output see my solution below
Sheet1 convert cell A1 value to number format enter in cell B1
=(A1-INT(A1))*24
In Sheet2 convert cell B to number format -> cell D
----------------------------------------------------------
| A | B | C | D |
|---------------------------------------------------------
| 1 | 07:36:00 | 08:23:10 | 7.6 | forumla "=(B12-INT(B12))*24"
| 2 | 08:23:10 | 09:10:20 | 8.386111111 |
| 3 | 09:10:20 | 09:57:30 | 9.172222222 |
| 4 | 09:57:30 | 10:44:40 | 9.958333333 |
| 5 | 10:44:40 | 11:31:50 | 10.74444444 |
| 6 | 11:31:50 | 12:19:00 | 11.53055556 |
| 7 | 12:19:00 | 13:06:10 | 12.31666667 |
| 8 | 13:06:10 | 13:53:20 | 13.10277778 |
| 9 | 13:53:20 | 14:40:30 | 13.88888889 |
| 10 | 14:40:30 | 15:27:40 | 14.675 |
| 11 | 15:27:40 | 16:14:50 | 15.46111111 |
| 12 | 16:14:50 | 17:02:00 | 16.24722222 |
| 13 | 17:02:00 | 18:14:50 | 17.03333333 |
| 14 | 18:14:50 | 19:27:40 | 18.24722222 |
| 15 | 19:27:40 | 20:40:30 | 19.46111111 |
| 16 | 20:40:30 | 21:53:20 | 20.675 |
| 17 | 21:53:20 | 23:06:10 | 21.88888889 |
| 18 | 23:06:10 | 00:19:00 | 23.10277778 |
| 19 | 00:19:00 | 01:31:50 | 0.316666667 |
| 20 | 01:31:50 | 02:44:40 | 1.530555556 |
| 21 | 02:44:40 | 03:57:30 | 2.744444444 |
| 22 | 03:57:30 | 05:10:20 | 3.958333333 |
| 23 | 05:10:20 | 06:23:10 | 5.172222222 |
| 24 | 06:23:10 | 07:36:00 | 6.386111111 |
---------------------------------------------------------
Now Sheet1 C1 enter the array forumla (shift + Ctrl + Enter)
=INDEX(Sheet2!A12:A35,MATCH(MIN(ABS(Sheet2!D12:D35-Sheet1!B1)),ABS(Sheet2!D12:D35-Sheet1!B1),0))
Sheet1 D1
=VLOOKUP(B3,Sheet2!A12:C35,2,FALSE)
Sheet1 E1
=VLOOKUP(B3,Sheet2!A12:C35,3,FALSE)
Output in Sheet1
------------------------------------------------------------------------------------
| A | B | C | D | E |
|-------------------------------------------------------------------|---------------|
| 07:36:58 | 7.615991667 | 1 | 07:36:00 | 08:23:10 |
-------------------------------------------------------------------------------------
Thanks

Expand a data set using two columns

In Excel, I have two columns of data that I wish to combine.
Current set of data:
+---------+---------+
| column1 | column2 |
+---------+---------+
| a | 1 |
| b | 2 |
| c | 3 |
| d | 4 |
| | 5 |
| | 6 |
| | 7 |
+---------+---------+
For each value in column1, I need to assign all of the values in column2 so it looks like this:
+---------+---------+
| column1 | column2 |
+---------+---------+
| a | 1 |
| a | 2 |
| a | 3 |
| a | 4 |
| a | 5 |
| a | 6 |
| a | 7 |
+---------+---------+
| b | 1 |
| b | 2 |
| b | 3 |
| b | 4 |
| b | 5 |
| b | 6 |
| b | 7 |
+---------+---------+
| c | 1 |
| c | 2 |
| c | 3 |
| c | 4 |
| c | 5 |
| c | 6 |
| c | 7 |
+---------+---------+
| d | 1 |
| d | 2 |
| d | 3 |
| d | 4 |
| d | 5 |
| d | 6 |
| d | 7 |
+---------+---------+
How can I do this?
Do I need to find a macro/VB solution?
Since seems unlikely to receive any other answer:
in A1: a
in B1: =MOD(ROW()-1,7)+1
in A2: =IF(MOD(ROW()-1,7)>0,CHAR(CODE(A1)),CHAR(CODE(A1)+1))
Copy both formulae down to suit.

Resources