Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Madmaxigail
Frequent Visitor

CountIf Measure

I may just be searching incorrectly, but I am looking to create a measure that would function like the "count if" function in Excel.

 

I am tracking number of incidents across time (columns) per day (rows).  I have multiple time of day columns with values ranging from 1 to 5.  I want to know how many times in each day (row) 1 incident occurs at a timeframe (column), how many times in each day (row) 2 incidents occurs at a timeframe (column), and so on. 

 

In Excel I can simply create 5 "countif" columns for each of the 5 values across all columns.

 

Here is a sample table...

Date10:0011:0012:0013:00
January 11112
January 21224
January 32531

 

So I would like to generate a measure that would count how many times 1 appeared on Jan 1.  In this example above it would return 3 as the answer.  And then I would create more measures for the other numbers of incidents (2, 3, 4, and 5) across all times for each date.  

 

Is this a possibility?  I actually have nearly 100 columns for each date in my dataset (every 15 minutes).

 

Thanks in advance.

3 REPLIES 3
Madmaxigail
Frequent Visitor

Sorry folks, I skipped a step in my dataset and need to go back to transform my data as I indicated in my example.  I am going to reframe my question.

v-yueyunzh-msft
Community Support
Community Support

Hi , @Madmaxigail 

Here are the steps you can refer to :

(1)My test data is the same as yours.

(2)We can unpivot the table in Power Query Editor, you can put this in the "Advanced Editor":

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8krMK00sqlQwVNJRQsZGSrE6CFkjuCgEm6DIGkNFTYHYGKwyNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"10:00" = _t, #"11:00" = _t, #"12:00" = _t, #"13:00" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"10:00", Int64.Type}, {"11:00", Int64.Type}, {"12:00", Int64.Type}, {"13:00", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Date"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Columns",{{"Attribute", "Time"}})
in
    #"Renamed Columns"

Then we can get this table:

vyueyunzhmsft_0-1667352913233.png

 

(3)Then we just need to put the filed on the Matrix table , we will meet your need ,the result is as follows:

vyueyunzhmsft_1-1667352947061.png

 

Best Regards,

Aniya Zhang

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

Ashish_Mathur
Super User
Super User

Hi,

In the Query Editor, right click on the first column and select "Unpivot Other Columns".  In the matrix visual, drag Date to the row labels and Value to the Column labels.  Write this measure

Count = countrows(Data)

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors