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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
v_mark
Helper V
Helper V

Translate Multiple Excel Countifs into DAX

I was trying to re-create 4 measures from Excel that uses Countifs ...

 

 

WIP - Inside SLA = COUNTIFS(Export!$B:$B,"<="&RM!G$5+1,Export!$C:$C,">="&RM!G$5+1,Export!$D:$D,">"&RM!G$5+1,Export!$E:$E,IF($E6="","*",RM!$E6))+
COUNTIFS(Export!$B:$B,"<="&RM!G$5+1,Export!$C:$C,">="&RM!G$5+1,Export!$D:$D,"",Export!$E:$E,IF($E6="","*",RM!$E6))

WIP - Failed SLA = =COUNTIFS(Export!$B:$B,"<="&RM!G$5+1,Export!$C:$C,"<"&RM!G$5+1,Export!$D:$D,">"&RM!G$5+1,Export!$E:$E,IF($E6="","*",RM!$E6))
+COUNTIFS(Export!$B:$B,"<="&RM!G$5+1,Export!$C:$C,"<"&RM!G$5+1,Export!$D:$D,"",Export!$E:$E,IF($E6="","*",RM!$E6))

Closed - Pass SLA = =COUNTIFS(Export!$D:$D,"<="&RM!G$5+1,Export!$D:$D,">"&RM!F$5+1,Export!$E:$E,IF($E6="","*",RM!$E6),Export!$F:$F,"pass")

Closed - Fail SLA = =COUNTIFS(Export!$D:$D,"<="&RM!G$5+1,Export!$D:$D,">"&RM!F$5+1,Export!$E:$E,IF($E6="","*",RM!$E6),Export!$F:$F,"fail")​​​

 

 

Here are the desired results. The ones highlighted in yellow. 

v_mark_0-1699603147438.png

I tried to build a date dimension together with my fact table and create relationship in between. 

I tried to create a couple of approaches but it looks like I am missing something in my DAX. 

v_mark_2-1699603340720.png

The result that I get is perfect in measure called New but almost close to the other shown above vs the desired results.

Each measure has it's own criteria that goes with a specific date field inside the fact table like Submitted, Target and Close Dates. 

Do you guys have an idea what I am missing? Any idea or suggestion is highly appreciated!

For quick reference Here's the link Power BI
Sample PBIX and Excel File ( for the desired Results )

 

 

 

 

 

3 REPLIES 3
lbendlin
Super User
Super User

Forget Excel.  Describe your business rules .  

 

Avoid nesting measures.  For example:

 

_Closed - Pass SLA = 
VAR _weekending = MAX('Dates'[Week Ending Date])
RETURN  COALESCE(CALCULATE(
    COUNTROWS(Test),
    'Test'[Pass/Fail] = "Pass",
    'Test'[Close Out Date] <= _weekending,
    USERELATIONSHIP(Dates[Date],Test[Close Out Date])
),0)

@lbendlin - I know getting a concrete understanding about the process would be valuable. 
Just a question please. When you say "Avoid nesting Measures" What do you mean by that?. I saw you paste a measure that has a several DAX on it. Is that the one you are pertaining at? 

 

You used CALCULATE([_test Close Date],..)  which I replaced by CALCULATE(COUNTROWS(Test),...) - that makes it clearer what is happening, and avoids confusion on context transitions.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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