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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
croberts21
Continued Contributor
Continued Contributor

How to sum Hours by year and month in format YYYY/MM?

I have Free PBI Desktop v2.100.1182 (64 bit free version) on Windows 10. I'm still pretty new to PBI and work on it in my limited spare time.

 

I have 2 fields on a single table. The table is Jobcost. The fields are STARTDATE and HOURS and EMPID. I have the filter set to show only me as the EMPID. There can be multiple STARTDATE and HOURS per day. I want to sum the hours by month and year. I'm having trouble making a measure which shows the month and year as Format() gives me an error.

 

I've been doing research for about 90 minutes and have not succeeded in getting this working. Here are the measures I have tried:

 

Date_Month = FORMAT(Jobcost[Startdate],"YYYY/MM")

The error I get for this one is: "A single value for column 'startdate' in table 'Jobcost' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, "

 

Date_Month = FORMAT(RELATED(Jobcost[Startdate]),"YYYY/MM")

The error for this one is: "The column 'Jobcost[startdate]' either doesn't exist or doesn't have a relationship to any table available in the current context."

 

The Jobcost table has 9 million records.

 

Any ideas how I can get this to work? Thank you!

 

EDIT: Made field name "Startdate" more consistent in this post.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @croberts21 ,

 

I make a simple like below.

vcgaomsft_0-1646125211946.png

Please create a calculated column.

 

aaMonthNum = FORMAT('Jobcost'[STARTDATE]+TIME(0,0,0),"mm/yyyy")

 

And then create a measure like this.

 

aaTotalHrs = SUM('Jobcost'[HOURS])

 

Then drag them into the visual.

vcgaomsft_0-1646189136491.png

Attach the pbix file for reference. Hope it helps.

 

Best Regards,
Community Support Team_Gao


If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @croberts21 ,

 

I make a simple like below.

vcgaomsft_0-1646125211946.png

Please create a calculated column.

 

aaMonthNum = FORMAT('Jobcost'[STARTDATE]+TIME(0,0,0),"mm/yyyy")

 

And then create a measure like this.

 

aaTotalHrs = SUM('Jobcost'[HOURS])

 

Then drag them into the visual.

vcgaomsft_0-1646189136491.png

Attach the pbix file for reference. Hope it helps.

 

Best Regards,
Community Support Team_Gao


If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

croberts21
Continued Contributor
Continued Contributor

Thank you that works! But it wasn't sorting the dates right so i changed the date format to yyyy-mm and it sorted correctly by date. PBI doesn't treat this field as a date for some reason.

amitchandak
Super User
Super User

@croberts21 , id adte do no have any time stamp  then in visual put

STARTDATE

and a measure

total = sum(table[hours])

 

assuming hours is a number

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

II added this measure:

aaTotalHrs = Sum(Jobcost[jcacthours])
(the Hours field is actually called "jcacthours".)
 
So I end up with the field "jcstartdate" and my measure aaTotalHrs. It still sums by day, not by month and year.
 

The output should be by month and year like:

11/2021 10

12/2021 11

1/2022 12

2/2022 13

I made up the total hours per month.

 

I even tried to make a Measure that shows the year and month like this:

aaMonthNum = Format(Jobcost[startdate],"YYYY/MM")
 
But I get the error:
"A single value for column 'startdate' in table 'Jobcost' cannot be determined.
This can happen when a measure formula refers to a column that contains many
values without specifying an aggregation such as min, max, "
 

 

 

 

 

croberts21_0-1646131687727.png

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors