Count null or specific value in a row and display counter in the same row

YaseenAli

New Member
Joined
May 4, 2022
Messages
8
Office Version
  1. 2021
Platform
  1. Windows
Hi,

Consider the following table, it is an exam record for students.

There is a name column at the start and then the
VBA Code:
Semester Check
column and Semester 1 till Semester 6 columns.

I want to
  1. Find the missing represented by null,
  2. The failures (any value < .4) and
  3. Want to display the failure and missing counter in the Semester Check column


Student NameSemester CheckSemester 1Semester 2Semester 3Semester 4Semester 5Semester 6
Student 1M-1 F-00.440.580.60.54null0.88
Student 3M-2 F-0nullnull0.640.480.440.52
Student 2M-0 F-10.460.560.340.440.680.66
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Book1
ABCDEFGHIJ
1Student NameSemester CheckSemester 1Semester 2Semester 3Semester 4Semester 5Semester 6MissingFailures
2Student 1M-1 F-00.440.580.60.54null0.8810
3Student 3M-2 F-0nullnull0.640.480.440.5220
4Student 2M-0 F-10.460.560.340.440.680.6601
Sheet2
Cell Formulas
RangeFormula
I2:I4I2=COUNTIFS(C2:H2,"=null")
J2:J4J2=COUNTIFS(C2:H2,"<"&0.4)
Add the two columns to get the total of both. If you want only one column with the total of both, add the two COUNTIFS statements in one column.
 
Upvote 0
Book1
ABCDEFGHIJ
1Student NameSemester CheckSemester 1Semester 2Semester 3Semester 4Semester 5Semester 6MissingFailures
2Student 1M-1 F-00.440.580.60.54null0.8810
3Student 3M-2 F-0nullnull0.640.480.440.5220
4Student 2M-0 F-10.460.560.340.440.680.6601
Sheet2
Cell Formulas
RangeFormula
I2:I4I2=COUNTIFS(C2:H2,"=null")
J2:J4J2=COUNTIFS(C2:H2,"<"&0.4)
Add the two columns to get the total of both. If you want only one column with the total of both, add the two COUNTIFS statements in one column.
Hi,
Thanks for the reply but I'm looking for a PowerQuery solution
 
Upvote 0
Hi,
Thanks for the reply but I'm looking for a PowerQuery solution
Sorry, but all I got is using a conditional column for each semester and adding the columns together, but that's rediculous. I'm sure there's a few that can come up with something better!
 
Upvote 0
Question resolved

I was searching the forum and found this thread similar to my issue, I solved my problem through following code


Power Query:
semMissingCheck = Table.AddColumn(removeOtherCir, "SEE Missing", each ((if [#"Semester 1"] = null then 1 else 0) + (if [#"Semester 2"] = null then 1 else 0) + (if [#"Semester 3"] = null then 1 else 0) + (if [#"Semester 4"] = null then 1 else 0) + (if [#"Semester 5"] = null then 1 else 0) + (if [#"Semester 6"] = null then 1 else 0)) ),

semFailCheck = Table.AddColumn(semMissingCheck, "SEE Fail", each ((if [#"Semester 1"] = null then 0 else if [#"Semester 1"] <.4 then 1 else 0) + (if [#"Semester 2"] = null then 0 else if [#"Semester 2"] <.4 then 1 else 0) + (if [#"Semester 3"] = null then 0 else if [#"Semester 3"] <.4 then 1 else 0) + (if [#"Semester 4"] = null then 0 else if [#"Semester 4"] <.4 then 1 else 0) + (if [#"Semester 5"] = null then 0 else if [#"Semester 5"] <.4 then 1 else 0) + (if [#"Semester 6"] = null then 0 else if [#"Semester 6"] <.4 then 1 else 0))),


addPrefix1 = Table.TransformColumns(semFailCheck, {{"SEE Missing", each "M-" & Text.From(_, "en-US"), type text}}),
addPrefix2 = Table.TransformColumns(addPrefix1, {{"SEE Fail", each "F-" & Text.From(_, "en-US"), type text}}),
mergeSem = Table.CombineColumns(addPrefix2,{"SEE Fail", "SEE Missing"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Sem Check"),
 
Upvote 0
another way

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    scols = List.Select(Table.ColumnNames(Source), each Text.StartsWith(_,"Semester")),
    tbl = Table.AddColumn(Source, "Semester Check", each 
        let 
            lst = Record.ToList(Record.SelectFields(_, scols)),
            m = List.Count(List.Select(lst, (x)=>x=null)),
            f = List.Count(List.Select(lst, (x)=>x<.4))
        in 
            "M-" & Text.From(m) & " " & "F-" & Text.From(f)
    ),
    Result = Table.ReorderColumns(tbl, {"Student Name", "Semester Check"} & scols)
in
    Result

Book2
ABCDEFGHIJKLMNOPQ
1Student NameSemester 1Semester 2Semester 3Semester 4Semester 5Semester 6Student NameSemester CheckSemester 1Semester 2Semester 3Semester 4Semester 5Semester 6
2Student 10.440.580.60.540.88Student 1M-1 F-00.440.580.60.540.88
3Student 30.640.480.440.52Student 3M-2 F-00.640.480.440.52
4Student 20.460.560.340.440.680.66Student 2M-0 F-10.460.560.340.440.680.66
5
Sheet1
 
Upvote 1
Solution
Thanks, you
another way

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    scols = List.Select(Table.ColumnNames(Source), each Text.StartsWith(_,"Semester")),
    tbl = Table.AddColumn(Source, "Semester Check", each
        let
            lst = Record.ToList(Record.SelectFields(_, scols)),
            m = List.Count(List.Select(lst, (x)=>x=null)),
            f = List.Count(List.Select(lst, (x)=>x<.4))
        in
            "M-" & Text.From(m) & " " & "F-" & Text.From(f)
    ),
    Result = Table.ReorderColumns(tbl, {"Student Name", "Semester Check"} & scols)
in
    Result

Book2
ABCDEFGHIJKLMNOPQ
1Student NameSemester 1Semester 2Semester 3Semester 4Semester 5Semester 6Student NameSemester CheckSemester 1Semester 2Semester 3Semester 4Semester 5Semester 6
2Student 10.440.580.60.540.88Student 1M-1 F-00.440.580.60.540.88
3Student 30.640.480.440.52Student 3M-2 F-00.640.480.440.52
4Student 20.460.560.340.440.680.66Student 2M-0 F-10.460.560.340.440.680.66
5
Sheet1
Thanks.
Your solution is much more elegant than the "if then else" code I was doing
 
Upvote 0

Forum statistics

Threads
1,215,452
Messages
6,124,914
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top