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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.