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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
poweruser55
Helper IV
Helper IV

Multiple conditions in measure

How can I do multiple conditions in a measure? Right now I have this - 

Ship = calculate(count('Table1'[OLI Number]),filter('Table1','Table1'[SD (Flag)]="Y")+0, filter('Table1','Table1'[Status]="Active"))
But this does not work, I need two condiitons, the flag = "Y" and Status= "Active" how can I do this?
1 ACCEPTED SOLUTION
bcdobbs
Super User
Super User

Try the following. Only thing I wasn't sure on was what you were trying to do with the +0. Are you trying to remove blanks? I don't think it's needed with a predicate like that.


Ship =

CALCULATE (

   COUNTROWS 'Table1' )

   'Table1'[SD (Flag)] = "Y",

   'Table1'[Status] = "Active",

   NOT ( ISBLANK ( 'Table1'[OLI Number] ) )

)



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

View solution in original post

9 REPLIES 9
bcdobbs
Super User
Super User

Try the following. Only thing I wasn't sure on was what you were trying to do with the +0. Are you trying to remove blanks? I don't think it's needed with a predicate like that.


Ship =

CALCULATE (

   COUNTROWS 'Table1' )

   'Table1'[SD (Flag)] = "Y",

   'Table1'[Status] = "Active",

   NOT ( ISBLANK ( 'Table1'[OLI Number] ) )

)



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

The number still seems way too high.. That filters both in that table for Flag = Y and status = active? @bcdobbs 

Yes, it should be!

 

If you go into the table view you should be able to apply the same filters and see what rows you have which might give a clue as to why it's too high.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

Ok so if I wanted to add the same thing but chnage the status to = lost I could just copy the formula and add a + sign and change the status. So I need all conditions to be true for each separate statement.  

CALCULATE (

   COUNTROWS 'Table1' )

   'Table1'[SD (Flag)] = "Y",

   'Table1'[Status] = "Active",

   NOT ( ISBLANK ( 'Table1'[OLI Number] ) +

CALCULATE (

   COUNTROWS 'Table1' )

   'Table1'[SD (Flag)] = "Y",

   'Table1'[Status] = "Lost",

   NOT ( ISBLANK ( 'Table1'[OLI Number] ) )

)

 )

) I just need to make sure I am not double counting. Also why do you not need to put a filter function? I thought that would be needed for each column. @bcdobbs 

Yes that's right just need a calculate for each expression and can indeed separate with + sign.

 

So for single column filters like the ones above, CALCULATE can take a simple predicate like Table1[Status] = "lost". Under the surface it turns it into a full filter statement itself. It's referred to as syntax sugar; just makes it easier to read.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

I posted this here, it is using the same logic as this question if you could please take a look. I'm very stuck here. https://community.powerbi.com/t5/Desktop/Count-at-least-one-flag/m-p/2390129 @bcdobbs 

I have a few of these flag columns I need to add together. The problem is I don't want to double count them. Using the oli number to count how can I make sure that it is only counting a unique oli number for each measure that contains the flag and other criteria? @bcdobbs for example I have another measure 

CALCULATE (

   COUNTROWS 'Table1' )

   'Table1'[Another (Flag)] = "Y",

   'Table1'[Status] = "Active",

   NOT ( ISBLANK ( 'Table1'[OLI Number] ) 

I need another measure that counts each oli from both measure but it has to be unique so it doesn't double count. Because an oli number can have any number of flags. @bcdobbs Basicslly each measure counts then I need to add up all the measures together and count for when there is AT LEAST one Oli number with a flag. But if it has 3 flags I only want one to count for the total.

Ok in that case you don't want to add sepearate calculates.


Instead do it all inside one calculate with a set of filters that return all possible rows including duplicates. Then use DISTINCTCOUNT of your oli column instead of COUNTROWS.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

I don't think that will work. There are overlapping filters. They have to be done separately then combined. Separate measures then a combined count of the distinct oli numbers @bcdobbs 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.