Forum Discussion
Can a Measure sum other rows besides itself?
- 8 years ago
Hi, try with this measure:
Does ID Have Only Blue? = IF ( HASONEVALUE ( Table1[ID] ), IF ( SELECTEDVALUE ( Table1[Color] ) = "Blue", IF ( COUNTROWS ( FILTER ( ALL ( Table1 ), Table1[ID] = SELECTEDVALUE ( Table1[ID] ) ) ) = 1, "Yes", "No" ), "No" ) )Regards
Victor
Lima - Peru
How about this
Measure =
CALCULATE (
AND ( CONTAINS ( 'Table', 'Table'[Colour], "Blue" ), COUNTROWS ( 'Table' ) = 1 ),
FILTER ( ALL ( 'Table' ), 'Table'[ID] = SELECTEDVALUE ( 'Table'[ID] ) )
)Hi Matt,
Thanks for the quick reply...
But sorry, can you help me understand what that first "AND" is doing there? I'm not quite sure I follow that one...
- dtartaglia8 years ago
Resolver I
Hi Matt,
I may be cofused by the question but if I create your table in Excel, the below measure will show your results:
ID Blue = IF(VALUES(Sheet1[ID]) = 4 && VALUES(Sheet1[color]) = "blue", "YES", "no")
- GTS_ONE8 years ago
Advocate II
Hi,
Well, basically I'm trying to do the measure without knowing which IDs are ONLY Blue. So in this case, I want the ID #4 want to be flagged, but I don't know that in advance.
I need the measure to flag #4 which is only Blue, but not #3, which has both Blue and Red rows.
- Vvelarde8 years ago
Community Champion
Hi, try with this measure:
Does ID Have Only Blue? = IF ( HASONEVALUE ( Table1[ID] ), IF ( SELECTEDVALUE ( Table1[Color] ) = "Blue", IF ( COUNTROWS ( FILTER ( ALL ( Table1 ), Table1[ID] = SELECTEDVALUE ( Table1[ID] ) ) ) = 1, "Yes", "No" ), "No" ) )Regards
Victor
Lima - Peru
- MattAllington8 years ago
Community Champion
dtartaglia wrote:I may be cofused by the question but if I create your table in Excel, the below measure will show your results:
ID Blue = IF(VALUES(Sheet1[ID]) = 4 && VALUES(Sheet1[color]) = "blue", "YES", "no")
the problem with this formula is that it only works for the test data loaded. What will this formula do if there is a new row of test data with ID = 5 and color = "blue". Your formula will return no, mine will return true
- MattAllington8 years ago
Community Champion
GTS_ONE wrote:
But sorry, can you help me understand what that first "AND" is doing there? I'm not quite sure I follow that one...You secenario requires 2 things to be true.
1. The row must have blue as the colour.
2. Assuming 1 is true, there must also not be another row in the table with the same ID
the AND function is checking for both of these separately. the CONTAINS checks if the current row is blue, the second parameter of AND (countrows(table) checks if there are other rows that exist.