Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
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 day | Count into area | Count leaving area |
0 | 2 | 6 |
1 | 3 | 8 |
2 | 4 | 0 |
3 | 0 | 0 |
4 | 6 | 0 |
5 | 0 | 2 |
6 | 0 | 1 |
7 | 5 | 3 |
Thank you in advance,
Step 0: I use these data.
Step 1: I add a 'Date' column on Power Query Editor.
- Before -
- After -
Step 2: I add a 'Time' column on Power Query Editor.
- Before -
- After -
Step 3: I change the type of 'Time' column.
'Time' column: 'Time' --> 'Decimal Number'
Step 4: I add a 'Hour' column below.
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.
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!!
Proud to be a Super User! | |
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
81 | |
75 | |
60 | |
37 | |
33 |
User | Count |
---|---|
102 | |
56 | |
52 | |
46 | |
40 |