0

I have a table like this

Input file as mobile numbers and their daily data usage in MB

I want output as Dates in one column and count of mobile numbers on each date which has crossed 150 MB of usage along with the sum of their usage in the next column.

Output

SAMPLE INPUT:

mobile_no,1-Sep-17,2-Sep-17,3-Sep-17,4-Sep-17,5-Sep-17
33045,50,110,200,100,34
33046,23,123,30,480,230
33047,102,217,23,145,186
33048,165,201,230,230,149
33049,22,229,160,71,173

Dau_uaD
  • 88
  • 1
  • 9

2 Answers2

4

In Cell H2 enter the following formula

=OFFSET($A$1,0,ROW()-1)

Then in Cell I2 enter

=SUMPRODUCT(($B$1:$F$1=H2)*($B$2:$F$6>150))

Finally in Cell J2 enter

=SUMPRODUCT(($B$1:$F$1=H2)*($B$2:$F$6>150)*($B$2:$F$6))

Drag/Copy down formulas as required. Change the range as per your data. See image for reference.

enter image description here

Mrig
  • 11,612
  • 2
  • 13
  • 27
1

In R, we can gather it to 'long' format, then grouped by the 'Date' column, get the number of 'mobile_no' and also the sum of 'val'

library(tidyverse)
df1 %>%
    gather(Date, val, -mobile_no) %>%
    filter(val > 150) %>%
    group_by(Date) %>%
    summarise(Count = n(), Sum_of_Usage = sum(val))
# A tibble: 5 x 3
#      Date Count Sum_of_Usage
#      <chr> <int>        <dbl>
#1 1-Sep-17     1          165
#2 2-Sep-17     3          647
#3 3-Sep-17     3          590
#4 4-Sep-17     2          710
#5 5-Sep-17     3          589
akrun
  • 874,273
  • 37
  • 540
  • 662