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
Anonymous
Not applicable

exists in same table

hi, i'm new to Power BI...

not sure if i need a calculated column or a measure.

I want to check for each row if another row exists where value in column A is the same as this row and value in column B is 1.

so basically I would have a new boolean column.

or, optionally to have a new table with distinct columns A, B and the new bool column.

 

how should i do that in DAX and sould it be a column or a measure?

thanks

1 ACCEPTED SOLUTION

@Anonymous ,

 

Create two measures using DAX below:

count with true = CALCULATE(DISTINCTCOUNT('Table'[A]), FILTER(ALLEXCEPT('Table', 'Table'[B]), 'Table'[C] = TRUE()))
count with false = CALCULATE(DISTINCTCOUNT('Table'[A]), FILTER(ALLEXCEPT('Table', 'Table'[B]), 'Table'[C] = FALSE()))

Capture.PNG 

 

Community Support Team _ Jimmy Tao

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

View solution in original post

5 REPLIES 5
PattemManohar
Community Champion
Community Champion

@Anonymous  You can use a conditional column to flag row alreayd exists or not. But it will be great if you can post some sample data and expected output to suggest an accurate solution.





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




Anonymous
Not applicable

thank you @PattemManohar !

lets say i have the following data:  (ignore column D, it's only to show that data is distinct)

 

ex.png

 

 

 

 

 

 

(of course real data is much bigger)

I need a report (or a graph) that will count distinct countries for each president that have at least one true value in column C.  and a count of countries without any true value.

so the report would be like that:

 

ex2.png

 

 

I guess there are a few ways to do that, but i'm not sure how...

Thanks a lot

 

I know my original question didn't mention all that Smiley Happy  I was just trying to simplify

@Anonymous  Please follow below steps:

 

Add a new column in the source table as below. This is to flag all the states as True if it contains atleast one True value.

 

 

CheckFlag = 
VAR _CurrState = Test191Lkp[State]
VAR _CurrPresident = Test191Lkp[President]
VAR _Result = LOOKUPVALUE(Test191Lkp[Flag],Test191Lkp[State],_CurrState,Test191Lkp[President],_CurrPresident,Test191Lkp[Flag],TRUE)
RETURN IF(ISBLANK(_Result),"F","T")

 

 

The result will now looks like..

 

image.png

 

Now create a new table as below which will use the above table as input.

 

Test191Out = 
VAR _True = SUMMARIZE(FILTER(Test191Lkp,Test191Lkp[CheckFlag]="T"),Test191Lkp[President],"TrueCount",DISTINCTCOUNT(Test191Lkp[State]),"Type","True")
VAR _False = SUMMARIZE(FILTER(Test191Lkp,Test191Lkp[CheckFlag]="F"),Test191Lkp[President],"FalseCount",DISTINCTCOUNT(Test191Lkp[State]),"Type","False")
RETURN UNION(_True,_False)

The output will be 

 

image.png

 

Now you can see the Matrix visual to represent this data in your required fashion.

 

image.png

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




@Anonymous ,

 

Create two measures using DAX below:

count with true = CALCULATE(DISTINCTCOUNT('Table'[A]), FILTER(ALLEXCEPT('Table', 'Table'[B]), 'Table'[C] = TRUE()))
count with false = CALCULATE(DISTINCTCOUNT('Table'[A]), FILTER(ALLEXCEPT('Table', 'Table'[B]), 'Table'[C] = FALSE()))

Capture.PNG 

 

Community Support Team _ Jimmy Tao

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

Anonymous
Not applicable

@PattemManohar and @v-yuta-msft great thanks!!

(i think i'm missing the accept bottun... where is it?)

found it Robot LOL

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.

Top Solution Authors