Forum Discussion

Pivotable78's avatar
Pivotable78
New Member
4 years ago
Solved

CountIF by rows in multiple columns on powerquery

Hi,

 

I'm struglling to find solution to do this in power query and didn't find here :

I get a report from salesforces that shows activity by sales reps by day that i load on power query.

 

it looks like this (without red columns) :

 

RepMondayTuesdayWednesdayThursdayFridayDate
On fieldout of field
Name AOn fieldOn fieldOn fieldout of fieldout of fieldNovember
32
Name BOn fieldout of fieldout of fieldout of fieldout of fieldNovember
1

4

Name AOn fieldOn fieldOn fieldOn fieldOn fieldDecember
5

0

 

What I want is to sum for each month the number of values "On field" and "out of field"  like the red columns then fill another file with xlookup.

 

 

Thank you for your helpπŸ™

  • Hi Pivotable78 ,

    According to your description, here's my solution.

    1. In Power Query, select the columns "Monday, Tuesday, Wednesday, Thursday, Friday" (Ctrl+select).

    2. Click "Unpivot Columns" tab under the Transform ribbon.

    Get this table.

    3.Create two measures.

    Count on field =
    CALCULATE (
        COUNT ( 'Table'[Value] ),
        ALLEXCEPT ( 'Table', 'Table'[Rep], 'Table'[Month] ),
        'Table'[Value] = "On field"
    )
    
    Count out field =
    CALCULATE (
        COUNT ( 'Table'[Value] ),
        ALLEXCEPT ( 'Table', 'Table'[Rep], 'Table'[Month] ),
        'Table'[Value] = "Out of field"
    ) + 0
    

    Get the result.

    I attach my sample below for reference.

     

    Best Regards,
    Community Support Team _ kalyj

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

3 Replies

  • Hi Pivotable78 ,

    According to your description, here's my solution.

    1. In Power Query, select the columns "Monday, Tuesday, Wednesday, Thursday, Friday" (Ctrl+select).

    2. Click "Unpivot Columns" tab under the Transform ribbon.

    Get this table.

    3.Create two measures.

    Count on field =
    CALCULATE (
        COUNT ( 'Table'[Value] ),
        ALLEXCEPT ( 'Table', 'Table'[Rep], 'Table'[Month] ),
        'Table'[Value] = "On field"
    )
    
    Count out field =
    CALCULATE (
        COUNT ( 'Table'[Value] ),
        ALLEXCEPT ( 'Table', 'Table'[Rep], 'Table'[Month] ),
        'Table'[Value] = "Out of field"
    ) + 0
    

    Get the result.

    I attach my sample below for reference.

     

    Best Regards,
    Community Support Team _ kalyj

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.