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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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