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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Brennan
New Member

Visuals error when using CALCULATE function in a Measure

I have two tables, Headcounts and Time. In Headcounts, I have a time_id and in Time I have the time_id as a primary key that tells you the time in hour format (12 hours).

 

Ex) time_id of 1 has a time_12 of 7:00 AM

 

the 7:00 AM value is of type text. I am trying to make a function of CALCULATE(AVG(headcounts), 'Time'[time_12]) so that when I apply an hour filter to the visual it won't change my Measure. I am getting this error: MdxScript(Model) (7, 166) Claculation error in measure'headocunts'[AVG HC NO Filters]: Cannot convert value '7:00 AM' of type Text to type True/False

 

Why I am confused is if I use the time_id in the same table, the visual will show.

 

Thank you for any help.

1 ACCEPTED SOLUTION
v-huizhn-msft
Microsoft Employee
Microsoft Employee

Hi @Brennan,

When you use CALCULATE function, you need to add a filter like CALCULATE(<expression>,<filter1>,<filter2>…). The filter must return the True/False to filter your table. You just use 'Time'[time_12], which can not return True/False value, so you got the error message. Please change your formula as follows, and check if it's the result you want.

measure=CALCULATE(AVG(headcounts), ALL('Time'[time_12]))


If you would not get the expected result, please share dummy data and list expected result for further analysis.

Thanks,
Angelia

View solution in original post

1 REPLY 1
v-huizhn-msft
Microsoft Employee
Microsoft Employee

Hi @Brennan,

When you use CALCULATE function, you need to add a filter like CALCULATE(<expression>,<filter1>,<filter2>…). The filter must return the True/False to filter your table. You just use 'Time'[time_12], which can not return True/False value, so you got the error message. Please change your formula as follows, and check if it's the result you want.

measure=CALCULATE(AVG(headcounts), ALL('Time'[time_12]))


If you would not get the expected result, please share dummy data and list expected result for further analysis.

Thanks,
Angelia

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.