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.
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?
Output that I want to see:
Thanks,
Ritesh
Solved! Go to Solution.
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
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
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
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
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
@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.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
96 | |
93 | |
82 | |
70 | |
64 |
User | Count |
---|---|
115 | |
106 | |
96 | |
81 | |
72 |