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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Sarath5c8
Frequent Visitor

Distinct Count of Value by Count of ID

I have an issue, it appeared simple but not getting the desired output. Below mentioned table should be in such a way that One ID is assigned to One Name i.e 1-1 mapping. Anything else is an invalid scenario.My goal is to tell what is the count of invalid scenarios present. 
REQUIRED OUTPUT is FLAG of 1 if invalid and 0 for Valid so that i can take sum of all the invalid
In the below table there are two invalid scenarios ie. one name - multiple ids (ABC is assigned to 01,02) and one id - multiple names (SDF & SDT - 03). 
I tried this but i feel there is a missing piece in it. 

1 Name|* ID =
var d=CALCULATE(MIN(tbl[ID]),ALLEXCEPT(tbl,tbl[NAME]))
return IF(tbl[ID]<>d,1,0)
NameId
ABC01
DEF02
ABC02
SDF03
SDT03
2 ACCEPTED SOLUTIONS
Samarth_18
Community Champion
Community Champion

Hi @Sarath5c8 ,

 

You can create a column like below:-

Column = 
var correct_value=CALCULATE(MIN('Table (2)'[Id]),FILTER('Table (2)','Table (2)'[Name] = EARLIER('Table (2)'[Name])))

return if(correct_value = [Id],0,1)

 

Output:-

Samarth_18_0-1648301795442.png

 

Thanks,

Samarth

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I think, in this sample, all of them are invalid cases.

ABC -> two ids

03 -> two names

02 -> two names

 

Please check the below picture and the attached pbix file.

 

Picture1.png

 

One Name One ID Invalid check CC =
VAR currentname = tbl[Name]
VAR currentid = tbl[Id]
VAR currentnametable =
    SUMMARIZE ( FILTER ( tbl, tbl[Name] = currentname ), tbl[Id] )
VAR currentidtable =
    SUMMARIZE ( FILTER ( tbl, tbl[Id] = currentid ), tbl[Name] )
RETURN
    SWITCH (
        TRUE (),
        COUNTROWS ( currentnametable ) <> 1, 1,
        COUNTROWS ( currentidtable ) <> 1, 1,
        0
    )

  

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I think, in this sample, all of them are invalid cases.

ABC -> two ids

03 -> two names

02 -> two names

 

Please check the below picture and the attached pbix file.

 

Picture1.png

 

One Name One ID Invalid check CC =
VAR currentname = tbl[Name]
VAR currentid = tbl[Id]
VAR currentnametable =
    SUMMARIZE ( FILTER ( tbl, tbl[Name] = currentname ), tbl[Id] )
VAR currentidtable =
    SUMMARIZE ( FILTER ( tbl, tbl[Id] = currentid ), tbl[Name] )
RETURN
    SWITCH (
        TRUE (),
        COUNTROWS ( currentnametable ) <> 1, 1,
        COUNTROWS ( currentidtable ) <> 1, 1,
        0
    )

  

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Samarth_18
Community Champion
Community Champion

Hi @Sarath5c8 ,

 

You can create a column like below:-

Column = 
var correct_value=CALCULATE(MIN('Table (2)'[Id]),FILTER('Table (2)','Table (2)'[Name] = EARLIER('Table (2)'[Name])))

return if(correct_value = [Id],0,1)

 

Output:-

Samarth_18_0-1648301795442.png

 

Thanks,

Samarth

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors