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
KRD
New Member

How to count two columns against the same value...

Hello,

 

I'm looking for some help in how to count two columns against the same value. The data is regarding visits into and out of an area (for example, a shop, or a ward in a hospital), I have the data split into date/time columns and then the into hour and out of hour, how do I create a table that shows by hour of the day, how many people went into the area, and a second column to show those leaving the area. Example below: 

 

Hour of the dayCount into areaCount leaving area
026
138
240
300
460
502
601
753

 

Thank you in advance,

2 REPLIES 2
mickey64
Super User
Super User

Step 0: I use these data.

mickey64_0-1721572004853.png

 

Step 1: I add a 'Date' column on Power Query Editor.

- Before -

mickey64_1-1721572065283.png

- After -

mickey64_2-1721572122870.png

 

Step 2: I add a  'Time' column on Power Query Editor.

- Before -

mickey64_3-1721572229010.png

- After -

mickey64_4-1721572247524.png

 

Step 3: I change the type of 'Time' column.

    'Time' column: 'Time' --> 'Decimal Number'

 

Step 4: I add a 'Hour' column below.

mickey64_5-1721572456237.png

 

Step 5: I change the type of 'Hour' column.

    'Hour' column: 'Decimal Number' --> 'Whole Number'

 

Step 6: I click 'Close & Apply'.

 

Step 7: I make a matrix on Power BI Desktop.

mickey64_6-1721572745627.png

 

rajendraongole1
Super User
Super User

Hi @KRD - Create a calculated table and in your dataset hope you have hour in and out columns. 

 

HourlySummary =
VAR IntoCounts =
SUMMARIZE (
'YourTableName',
'YourTableName'[Into Hour],
"Count Into Area", COUNTROWS('YourTableName')
)
VAR OutCounts =
SUMMARIZE (
'YourTableName',
'YourTableName'[Out Of Hour],
"Count Leaving Area", COUNTROWS('YourTableName')
)
RETURN
ADDCOLUMNS (
GENERATESERIES (0, 23, 1),
"Count Into Area",
COALESCE (LOOKUPVALUE (
IntoCounts[Count Into Area],
IntoCounts[Into Hour],
[Value]
), 0),
"Count Leaving Area",
COALESCE (LOOKUPVALUE (
OutCounts[Count Leaving Area],
OutCounts[Out Of Hour],
[Value]
), 0)
)

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.