Forum Discussion

PowerBI-Newbie's avatar
6 years ago
Solved

IF Statement with Multiple Columns/Criteria

Hi,

I have the following sample data:

Ref no.Part No. 1Part No. 2Part NameIssueStatusOwnerClosed Date
X1 B1Part 2    
X1A2B2Part 1YOpenPerson A 
X2  Part 3YClosedPerson B10/06/20
X3A4 Part 4YClosedPerson B06/06/20
X2A5 Part 5    
X5A6B6     
X4A7B7Part 7YOpenPerson C 

 

I need to calculate how many completed rows there are using the following:

  1. If column Issue is blank then it needs to count how many distinct rows (using column Ref No.) there are as well as ensuring column Part Name is not blank and either Part No. 1 or Part No. 2 is also not blank. For the above sample data the answer will be 2.
  2. If column Issue is Y then it needs to count how many distinct rows (using column Ref No.) there are as well as ensuring columns Part Name, OwnerClosed Date are not blank and either Part No. 1 or Part No. 2 is also not blank, and column Status is Closed. For the above sample data the answer will be 1.
  3. The measure (or measures) will calculate the above total and produce a grand total of 3 (adding the total of items 1 and 2).

 

I hope the above makes sense. Any help is greatly appreciated.

  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi PowerBI-Newbie ,

     

    Check the following measures.

    Measure1 = CALCULATE(DISTINCTCOUNT('Table'[Ref no.]),FILTER('Table','Table'[Issue]=BLANK()&&'Table'[Part Name]<>BLANK()&&('Table'[Part No. 1]<>BLANK()||'Table'[Part No. 2]<>BLANK())))
    
    Measure2 = CALCULATE(DISTINCTCOUNT('Table'[Ref no.]),FILTER('Table','Table'[Issue]="Y"&&('Table'[Part No. 1]<>BLANK()||'Table'[Part No. 2]<>BLANK())&&'Table'[Part Name]<>BLANK()&&'Table'[Owner]<>BLANK()&&'Table'[Closed Date]<>BLANK()&&'Table'[Status]="Closed"))
    
    Measure3 = SUMX('Table',[Measure1]+[Measure2])

     

    Best Regards,

    Jay

     

    Community Support Team _ Jay Wang

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

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi PowerBI-Newbie ,

     

    Check the following measures.

    Measure1 = CALCULATE(DISTINCTCOUNT('Table'[Ref no.]),FILTER('Table','Table'[Issue]=BLANK()&&'Table'[Part Name]<>BLANK()&&('Table'[Part No. 1]<>BLANK()||'Table'[Part No. 2]<>BLANK())))
    
    Measure2 = CALCULATE(DISTINCTCOUNT('Table'[Ref no.]),FILTER('Table','Table'[Issue]="Y"&&('Table'[Part No. 1]<>BLANK()||'Table'[Part No. 2]<>BLANK())&&'Table'[Part Name]<>BLANK()&&'Table'[Owner]<>BLANK()&&'Table'[Closed Date]<>BLANK()&&'Table'[Status]="Closed"))
    
    Measure3 = SUMX('Table',[Measure1]+[Measure2])

     

    Best Regards,

    Jay

     

    Community Support Team _ Jay Wang

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

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi PowerBI-Newbie ,

     

    Could you please show me the desired result based on the sample data? Excel or screenshot is fine.

     

    Thanks.

    Aiolos Zhao