• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member
  • Login

countifs or sumproduct in Power Query or Dax|Power Query|Excel Forum|My Online Training Hub

You are here: Home / countifs or sumproduct in Power Query or Dax|Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower Querycountifs or sumproduct in Power Que…
sp_PrintTopic sp_TopicIcon
countifs or sumproduct in Power Query or Dax
Avatar
Mario Santiago

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
September 8, 2019
sp_UserOfflineSmall Offline
1
September 8, 2019 - 7:12 pm
sp_Permalink sp_Print

Hi All,
How can I do Countifs or Sumproduct of dates in power query, dax/power pivot  ?

I have multiple columns with 2 dates columns.
I need to count the rows that meets the 2 dates criteria of status.

Criteria and objective: Count the rows if reported date is before status date; and other criteria is the current row of status date.

my data model has date table.

My challenge is getting the current row in Status date as criteria. Please see the sample data for more reference.

Reported Date Status Date Countifs Results
6/1/2019 6/10/2019 =COUNTIFS($A$2:$A$20,"<"&B2,$B$2:$B$20,B2) 2
6/2/2019 6/4/2019 =COUNTIFS($A$2:$A$20,"<"&B3,$B$2:$B$20,B3) 1
6/2/2019 6/3/2019 =COUNTIFS($A$2:$A$20,"<"&B4,$B$2:$B$20,B4) 1
6/6/2019 6/10/2019 =COUNTIFS($A$2:$A$20,"<"&B5,$B$2:$B$20,B5) 2
6/6/2019 6/6/2019 =COUNTIFS($A$2:$A$20,"<"&B6,$B$2:$B$20,B6) 0

 

Reported Date  Status Date Sumproduct Result
6/1/2019 6/10/2019 =SUMPRODUCT(($K$2:$K$7<L2)*($L$2:$L$7=L2)) 2
6/2/2019 6/4/2019 =SUMPRODUCT(($K$2:$K$7<L3)*($L$2:$L$7=L3)) 1
6/2/2019 6/3/2019 =SUMPRODUCT(($K$2:$K$7<L4)*($L$2:$L$7=L4)) 1
6/6/2019 6/10/2019 =SUMPRODUCT(($K$2:$K$7<L5)*($L$2:$L$7=L5)) 2
6/6/2019 6/6/2019 =SUMPRODUCT(($K$2:$K$7<L6)*($L$2:$L$7=L6)) 0

much thanks

Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4614
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
2
September 9, 2019 - 8:07 am
sp_Permalink sp_Print

Hi Mario,

Welcome to our forum! This is probably a job for Power Pivot, but it's difficult to tell from the data above. Please provide a sample Excel file with your data model if possible. 

Thanks,

Mynda

Avatar
Mario Santiago

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
September 8, 2019
sp_UserOfflineSmall Offline
3
September 9, 2019 - 9:34 pm
sp_Permalink sp_Print

Hi Mynda,

Much thanks for your reply. i have working on it for few days now. unable to crack the code.

please see sample file attached.

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1844
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
September 10, 2019 - 2:27 pm
sp_Permalink sp_Print

Hi Mario,

You should add a new column, here is the complete step:

NewColumn = Table.AddColumn(#"Changed Type", "CountIf", (x)=> Table.SelectRows(#"Changed Type",each x[#"Reported Date "] < [Status Date] and x[Status Date]=[Status Date]))

The new column will contain tables with only the matching records, you just have to expand this column, but choose aggregate instead of expand.

You will get the same countif functionality.

Avatar
Mario Santiago

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
September 8, 2019
sp_UserOfflineSmall Offline
5
September 11, 2019 - 12:50 am
sp_Permalink sp_Print

Hi Catalin,

Its is working!

however it is really slow when I tried it.

I have about 400K rows and growing. I had to terminate the process when I fist applied as this its taking too long just to do the counts.

 

I then tested it with about 500 rows with just 2 columns and still took me an approximately  a minute to load in.  am I doing really wrong here? can you please suggest a better way to do it, faster.

 

appreciate it very much.

thanks.

Avatar
Mario Santiago

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
September 8, 2019
sp_UserOfflineSmall Offline
6
September 11, 2019 - 1:24 am
sp_Permalink sp_Print

Hi Catalin,

I have noticed that it is counting the rows where the report date  is = status date.

example: report: 1/1,2019 , status: 1/1,2019 =1

answer should be 0.

the objective is : do not count if the report date is = to status date

please see test file.

thanks

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Yiwen Zhou, Martin Delloca, Joaquim Amorim, Rob Starren, Rob Rooth
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 880
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 237
Jessica Stewart: 219
A.Maurizio: 213
Aye Mu: 201
Hans Hallebeek: 183
Newest Members:
Rob Rooth
Tom Lewis
Jennifer Rodriguez-Avila
Khaled Ibrahim
Kiran Supekar
Lisa Myers
Ronald White
Ginette Guevremont
Taryn Ambrosi
Mark Davenport
Forum Stats:
Groups: 3
Forums: 24
Topics: 6531
Posts: 28604

 

Member Stats:
Guest Posters: 49
Members: 32821
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel Office Scripts
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook

Sign up to our newsletter and join over 400,000
others who learn Excel and Power BI with us.

 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate
  • Sponsor Our Newsletter

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.