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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DAX Calc Help

Hi,  I need help to create DAX calcs for last 2 columns below.  They are row level values but evaluated at aggregate project level.   Thanks!

 

ProjectTaskTask StatusProject Status (If a Project has any task open project is open, otherwise closed)Mixed Task Status (If a Proejct has more than one Task Status Type)
A1ClosedClosedFALSE
A2ClosedClosedFALSE
A3ClosedClosedFALSE
B1OpenOpenTRUE
B2ClosedOpenTRUE
B3ClosedOpenTRUE
C1OpenOpenFALSE
C2OpenOpenFALSE
1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

h1.png

 

You may create two measures as below.

Project Status = 
var result = 
CALCULATE(
    DISTINCTCOUNT('Table'[Task]),
    FILTER(
       ALLEXCEPT('Table','Table'[Project]),
       [Task Status]="Open"
    )
)
return
IF(
    result>0,
    "Open",
    "Closed"
)

 

Mixed Task Status = 
var result = 
CALCULATE(
    DISTINCTCOUNT('Table'[Task Status]),
    ALLEXCEPT('Table','Table'[Project])
)
return
IF(
    result>1,
    TRUE(),
    FALSE()
)

 

Result:

h2.png

 

Best Regards
Allan

 

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

4 REPLIES 4
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

h1.png

 

You may create two measures as below.

Project Status = 
var result = 
CALCULATE(
    DISTINCTCOUNT('Table'[Task]),
    FILTER(
       ALLEXCEPT('Table','Table'[Project]),
       [Task Status]="Open"
    )
)
return
IF(
    result>0,
    "Open",
    "Closed"
)

 

Mixed Task Status = 
var result = 
CALCULATE(
    DISTINCTCOUNT('Table'[Task Status]),
    ALLEXCEPT('Table','Table'[Project])
)
return
IF(
    result>1,
    TRUE(),
    FALSE()
)

 

Result:

h2.png

 

Best Regards
Allan

 

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

Anonymous
Not applicable

Allan, 

 

One further question on this.   I start to get quickly confused when additional functions are used WITHIN the CALCUALTE function.   What purpose does the ALLEXCEPT statement add to this calc?  When I look up the defintion of ALLEXCEPT it states:  "Removes all context filters in the table except filters that have been applied to the specified columns"

It seems to me it is ALSO controlling the context of which to evalaute the CALCULATE EXPRESSION.  It appears to be evaluating the context within the Project level.  

 

Can you explain what the ALLEXCEPT is doing?  Thanks!

Anonymous
Not applicable

Thank you!  This helps me tremendously!

parry2k
Super User
Super User

@Anonymous try these measures

 

Open/Close =
VAR __rows = CALCULATE ( COUNTROWS ( Table ), ALLEXCEPT ( Table, Table[Project] ), Table[Status] = "Open" ) 
RETURN
IF ( ISBLANK ( __rows ), "Closed", "Open" )

 

Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

March 2024 PBI Gallery Image

Power BI Monthly Update - March 2024

Check out the March 2024 Power BI update to learn about new features.