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
Ritesh_Air
Post Patron
Post Patron

Conditional Count with Omission

Hi Experts,

 

I have a unique problem where I want to exclude a row if my retailer shows in more than 1 row and I only want to keep the row with Program Desc as "Contractual"

 

Like in Below example:

 

Retailer 1, 2 and 6 have multiple rows. 

 

I want to only see 1 row each Program Desc as "Contractual".

 

How do I do that in DAX?

 

Contractual or Something Else.PNG

 

Output that I want to see:

Contractual or Something Else Compact.PNG

 

Thanks,

Ritesh

 

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey @Ritesh_Air ,

 

I'm wondering if it's possible that a retailer has multiple rows, but without having "contractual".

Basically you can create a new calculated column that checks the number of rows and if the description is contractual and flag the rows accordingly. The condition is like this

  • if there is just one row, keep the row
  • if there are more rows, then flag the row if description is "contractual"

this is my sample data:

 
 

and this is the DAX statement:

flag = 
var __retailer = 'Table'[Retailer]
var noofrows = COUNTROWS(FILTER(ALL('Table') , 'Table'[Retailer] = __retailer))
return
IF(noofrows = 1 
    , "keep"
    , IF('Table'[Program Desc] = "Contractual", "keep" , "omit")
)

Then you can use the column "keep" to filter the records.

 

Hopefully, this is what you are looking for.

 

Regards,
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

5 REPLIES 5
TomMartens
Super User
Super User

Hey @Ritesh_Air ,

 

I'm wondering if it's possible that a retailer has multiple rows, but without having "contractual".

Basically you can create a new calculated column that checks the number of rows and if the description is contractual and flag the rows accordingly. The condition is like this

  • if there is just one row, keep the row
  • if there are more rows, then flag the row if description is "contractual"

this is my sample data:

 
 

and this is the DAX statement:

flag = 
var __retailer = 'Table'[Retailer]
var noofrows = COUNTROWS(FILTER(ALL('Table') , 'Table'[Retailer] = __retailer))
return
IF(noofrows = 1 
    , "keep"
    , IF('Table'[Program Desc] = "Contractual", "keep" , "omit")
)

Then you can use the column "keep" to filter the records.

 

Hopefully, this is what you are looking for.

 

Regards,
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

@TomMartens 

 

Thanks Tom. It works perfectly. Just one question, probably we couldn't have done it with measures, eh?

 

Thanks again!

Hey @Ritesh_Air ,

you can create a measure that helps to decide if a row will be omitted or not.

 

But this will become more complex, as a measure always has to be considered in the context of a visual, and the existing filter context that is "formed" by slicers, axis label, row/column header inside the visual.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

@TomMartens this looks good but one question, why  ALLEXCEPT cannot be used? Just curious.

 

 

flag = 
var noofrows = CALCULATE ( COUNTROWS( 'Table' ) , ALLEXCEPT ( 'Table', 'Table'[Retailer]))
return
IF(noofrows = 1 
    , "keep"
    , IF('Table'[Program Desc] = "Contractual", "keep" , "omit")
)

 

 



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.

Thanks @TomMartensfor pointing, I fixed my measure, there was a typo. Cheers!! 



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

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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