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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Jhadur
Helper I
Helper I

Total Projects for Fiscal

I am trying to create a card that shows the total number of projects for the current fiscal year. I created the following measure but I am getting an error that seems to be related to the RETURN portion of the measure and I don't understand what the issue is. I am trying to count the number of projects started within the current fiscal year. The table has a line for each month a project update report was submitted, so each project has multiple lines and I need a count of the unique project codes.

 

TOTAL PROJECTS FOR FY = 
  VAR __MinDate = DATE( 2023, 11, 01 )
  VAR __MaxDate = DATE( 2024, 10, 31 )
  VAR __Table = FILTER( 'Projects', [Start] >= __MinDate && 'Projects'[Start] <= __MaxDate )
  VAR __CALCULATE = (COUNTROWS('Projects'),FILTER('Projects','Projects'[Project Code])
  RETURN
  __Result +0

 

This is the error I am getting.

 

Jhadur_0-1723746870088.png

 

1 ACCEPTED SOLUTION

Hi @Jhadur ,

It looks like there is an error in your DAX code that is preventing the data from being loaded. The error message states that the text value “BNSPRJOP230245” could not be converted to a True/False type. This is usually because the text value is used in a logical expression.

 

So I think you can just calculate the value returned by _Table. Here is my modified DAX code:

TOTAL PROJECTS FOR FY =
VAR __MinDate =
    DATE ( 2023, 11, 01 )
VAR __MaxDate =
    DATE ( 2024, 10, 31 )
VAR __Table =
    FILTER ( 'Projects', [Start] >= __MinDate && 'Projects'[Start] <= __MaxDate )
RETURN
    COUNTROWS ( __Table )

vyilongmsft_0-1724046033878.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Hi,

Try this approach

  1. Create a Calendar Table
  2. Build a relationship (Many to One and Single) from the Start column to the Calendar Table
  3. Write this measure

Measure = calculate(countrows(projects),datedbetween(calendar[date],date(2023,11,1),date(2024,10,30)))


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yilong-msft
Community Support
Community Support

Hi @Jhadur ,

I agree with what Idrissshatila said. So I create a table as you mentioned.

vyilongmsft_0-1723771409303.png

The reason for your error comes from the fact that __Result is not defined. You can output to variables in your VAR, which means that if you want to use __Result, you need to define the variable in a VAR to guarantee output.

Also I noticed that the following string of DAX code also has an error.

 VAR __CALCULATE = (COUNTROWS('Projects'),FILTER('Projects','Projects'[Project Code])

I modified it and the final DAX code is as follows:

TOTAL PROJECTS FOR FY =
VAR __MinDate =
    DATE ( 2023, 11, 01 )
VAR __MaxDate =
    DATE ( 2024, 10, 31 )
VAR __Table =
    FILTER ( 'Projects', [Start] >= __MinDate && 'Projects'[Start] <= __MaxDate )
VAR __CALCULATE =
    COUNTROWS ( FILTER ( 'Projects', 'Projects'[Project Code] ) )
RETURN
    __CALCULATE + 0

vyilongmsft_1-1723771673680.png

 

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you @v-yilong-msft that fixed the measure. However I am now getting this error in the card visualization. 

Jhadur_0-1723832809054.png

 

Hi @Jhadur ,

It looks like there is an error in your DAX code that is preventing the data from being loaded. The error message states that the text value “BNSPRJOP230245” could not be converted to a True/False type. This is usually because the text value is used in a logical expression.

 

So I think you can just calculate the value returned by _Table. Here is my modified DAX code:

TOTAL PROJECTS FOR FY =
VAR __MinDate =
    DATE ( 2023, 11, 01 )
VAR __MaxDate =
    DATE ( 2024, 10, 31 )
VAR __Table =
    FILTER ( 'Projects', [Start] >= __MinDate && 'Projects'[Start] <= __MaxDate )
RETURN
    COUNTROWS ( __Table )

vyilongmsft_0-1724046033878.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yilong-msft 

I need to make a couple changes to the way this measure is calculated. I need to count the unique project codes with a Forecast Delivery Date "after today". This should give an accurate count of current active projects, as many of our projects span multiple fiscal years. The table has a line for each month a project update report was submitted, so each project has multiple lines and I need a count of the unique project codes. I appreciate your assistance.

 

Project CodeOPProject NameStartFinishForecast Delivery DateSponsorReport StatusStatus Report Date
PRJ01OP01OP01 project 12022-03-012024-10-312024-10-31VP NameFinal2024-01-23
PRJ01OP01OP01 project 12022-03-012024-12-062024-12-06VP NameFinal2024-02-20
PRJ01OP01OP01 project 12022-03-012025-07-092025-07-09VP NameFinal2024-03-19
PRJ01OP01OP01 project 12022-03-012025-07-092025-07-09VP NameFinal2024-04-15
PRJ02OP02OP02 project 22024-05-012024-12-062024-12-06VP NameFinal2024-01-23
PRJ02OP02OP02 project 22024-05-012024-12-062024-12-06VP NameFinal2024-02-20
PRJ02OP02OP02 project 22024-05-012024-12-062024-12-06VP NameFinal2024-03-19
PRJ02OP02OP02 project 22024-05-012024-12-062024-12-06VP NameFinal2024-04-15

 

Thank you. This works perfectly. Appreciate the assistance.
Idrissshatila
Super User
Super User

Hello @Jhadur ,

 

regardless of the logic, you're returning a variable that is not defind.

 

if the last variable that returns the number is __calculate, then you should return __calculate



Did I answer your question? Mark my post as a solution! Appreciate your Kudos
Follow me on LinkedIn linkedIn
Vote for my Community Mobile App Idea

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 FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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