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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
mm_merchant
Frequent Visitor

Calculate Not working

Hi All, 

I have 2 tables: Projects and Risks where a 1:many relationship exists from Projects:Risks. The Risk table has a status column which is of type Choice ( 3 values): Active, Closed, Postponed

 

mm_merchant_0-1717427550937.png

mm_merchant_1-1717427603813.png

 

I need to show "Active" risks on a card visual in my report. The DAX I have is:

TestActive Risks =
VAR _totalrisks =
    COUNT ( Risk[Project ID])
VAR _onlyactive =
CALCULATE( _totalrisks,  Risk[pmotest_riskstatus] = "646440000", Risk[pmotest_riskstatus_display] = "Active")
RETURN    
    _onlyactive
 
This is returning all risks for that particular Project ID, instead what I need is filtered to only show "Active" ones as shown below:
mm_merchant_2-1717427954291.png

 

 On my visual, I have a slicer to select the Project from the Project Table, I expect it should show only the "Active" risks for that particular project. 
mm_merchant_3-1717428243654.png

What am I doing wrong here? 

1 ACCEPTED SOLUTION
v-jtian-msft
Community Support
Community Support

Hi,@mm_merchant .Hello,@Greg_Deckler,thanks for your concern about this issue.
And I would like to share some additional solutions below
I am glad to help you
There seems to be an error in your dax code, you can try this measure:

M_result = 
VAR _onlyactive =
CALCULATE(COUNT ( Risk[Project ID]), FILTER( 'Risk',Risk[pmotest_riskstatus] = "646440000" && Risk[pmotest_riskstatus_display] = "Active"))
RETURN    
    _onlyactive

 

In the calculate () function, the expression to be evaluated should not use variables as much as possible.


here is my test result

vjtianmsft_0-1717481423565.png

vjtianmsft_1-1717481433622.png

vjtianmsft_2-1717481442829.png

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

Best Regards,

Carson Jian,

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

5 REPLIES 5
v-jtian-msft
Community Support
Community Support

Hi,@mm_merchant .Hello,@Greg_Deckler,thanks for your concern about this issue.
And I would like to share some additional solutions below
I am glad to help you
There seems to be an error in your dax code, you can try this measure:

M_result = 
VAR _onlyactive =
CALCULATE(COUNT ( Risk[Project ID]), FILTER( 'Risk',Risk[pmotest_riskstatus] = "646440000" && Risk[pmotest_riskstatus_display] = "Active"))
RETURN    
    _onlyactive

 

In the calculate () function, the expression to be evaluated should not use variables as much as possible.


here is my test result

vjtianmsft_0-1717481423565.png

vjtianmsft_1-1717481433622.png

vjtianmsft_2-1717481442829.png

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

Best Regards,

Carson Jian,

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

 

Hello Carson,

I updated the DAX with your suggestion and I got it to work as expected. I tried the variation without the Filter function like this & it also worked:

VAR _getActiveRisks1 = CALCULATE( COUNT(Risk[Project ID]), Risk[pmotest_riskstatus] = "646440000", Risk[pmotest_riskstatus_display] = "Active")
 
thanks a lot for testing on your end. 

Hi,@mm_merchant 
I'm glad you solved your problem, if you have any other questions about power BI, you are welcome to share them on the forum as it will help more users with similar problems!

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

Best Regards,

Carson Jian,

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

Greg_Deckler
Super User
Super User

@mm_merchant Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi Greg, thanks for sharing the useful links. 

Sample data: 

Risk Table:

Project IDmsdyn_projectriskidpmotest_riskstatus_displaypmotest_riskstatus
73ae842e-dbab-41c8-b20d-360e6c6cbaf9956b3f32-4fa7-ee11-a568-002248b17b71Closed646440002
73ae842e-dbab-41c8-b20d-360e6c6cbaf9f01f3d1f-4fa7-ee11-a568-002248b17b71Active646440000
73ae842e-dbab-41c8-b20d-360e6c6cbaf91ab63111-4fa7-ee11-a568-002248b17b71Closed646440002
73ae842e-dbab-41c8-b20d-360e6c6cbaf93dbd91f8-4ea7-ee11-a568-002248b17b71Closed646440002
73ae842e-dbab-41c8-b20d-360e6c6cbaf9b7e580e0-4ea7-ee11-a568-002248b17b71Closed646440002
73ae842e-dbab-41c8-b20d-360e6c6cbaf91f09d039-3fa7-ee11-a568-002248b17b71Active646440000
73ae842e-dbab-41c8-b20d-360e6c6cbaf95e78bf8f-3ea7-ee11-a568-002248b17b71Closed646440002
73ae842e-dbab-41c8-b20d-360e6c6cbaf9b4621283-3ea7-ee11-a568-002248b17b71Closed646440002
73ae842e-dbab-41c8-b20d-360e6c6cbaf9b1b6d442-3ea7-ee11-a568-002248b17b71Closed646440002

 

The Project ID comes from Project Table and it is 1: Many relationship between Projects:Risks. 

On my visual I have the Project ID (or Project Name) slicer and what I expect is that the card visual should show only the Risks that have "pmotest_riskstatus_display" = "Active".

Project IDmsdyn_projectriskidpmotest_riskstatus_displaypmotest_riskstatus
73ae842e-dbab-41c8-b20d-360e6c6cbaf9f01f3d1f-4fa7-ee11-a568-002248b17b71Active646440000
73ae842e-dbab-41c8-b20d-360e6c6cbaf91f09d039-3fa7-ee11-a568-002248b17b71Active646440000

 

 

 

 

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!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.