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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
NAMLANI
New Member

How to weigh counts based on repeat values?

Hi,

 

I have the following Table1:

NameID
John111
John222
Jane333
Jane 111
Jane444

 

I get the counts of the IDs for each name like below (COUNTX('Table1', [ID])):

NameCount of ID
John2
Jane3

 

I'd like to weigh the counts of any matching values in the ID column by .5. So since John and Jane both have a 111, that count is now .5, resulting in:

NameCount of ID
John1.5
Jane2.5

 

I can't figure out how to write a function for this. Appreciate any assistance!

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@NAMLANI Perhaps something like this:

Measure = 
    VAR __Name = MAX('Table'[Name])
    VAR __WeightTable = SUMMARIZE(ALL('Table'),[ID],"__Weight",1/COUNTROWS('Table'))
    VAR __Table = ADDCOLUMNS('Table',"__Score",MAXX(FILTER(__WeightTable,[ID] = EARLIER('Table'[ID])),[__Weight]))
RETURN
    SUMX(__Table, [__Score])

Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

HI @NAMLANI  , @Greg_Deckler - I was going to suggest the following:

New Measure =
SUMX (
    ADDCOLUMNS (
        'Table',
        "ID Count",
            VAR _ID = 'Table'[ID]
            RETURN
                CALCULATE (
                    COUNTA ( 'Table'[ID] ),
                    REMOVEFILTERS ( 'Table' ),
                    'Table'[ID] = _ID
                )
    ),
    DIVIDE ( 1, [ID Count] )
)

 

Greg_Deckler
Super User
Super User

@NAMLANI Perhaps something like this:

Measure = 
    VAR __Name = MAX('Table'[Name])
    VAR __WeightTable = SUMMARIZE(ALL('Table'),[ID],"__Weight",1/COUNTROWS('Table'))
    VAR __Table = ADDCOLUMNS('Table',"__Score",MAXX(FILTER(__WeightTable,[ID] = EARLIER('Table'[ID])),[__Weight]))
RETURN
    SUMX(__Table, [__Score])

Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.