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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
BIswajit_Das
Impactful Individual
Impactful Individual

power bi loop

Present data

id  response

1       a        

1       b        

1       a        

2       a        

3       b        

Required Data

id  response   Maxcountbasedata

1       a               a

1       b               a

1       a               a

2       a               a

3       b               b

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @BIswajit_Das ,

I created a sample pbix file(see the attachment), please check if that is what you want.

1. Create a calculated column as below to get the count of per response under per id

Count = 
CALCULATE (
    COUNT ( 'Table'[response] ),
    FILTER (
        'Table',
        'Table'[id] = EARLIER ( 'Table'[id] )
            && 'Table'[response] = EARLIER ( 'Table'[response] )
    )
)

yingyinr_0-1677638642801.png

2. Create a measure as below to get the response which have the max count

Maxcountbasedata = 
VAR _selid =
    SELECTEDVALUE ( 'Table'[id] )
VAR _count =
    CALCULATE (
        MAX ( 'Table'[Count] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[id] = _selid )
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[response] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[id] = _selid
                && 'Table'[Count] = _count
        )
    )

yingyinr_1-1677638752124.png

Best Regards

View solution in original post

Anonymous
Not applicable

Hi @BIswajit_Das ,

You can create a calculated column as below to replace the measure, please find the details in the attachment.

Column =
VAR _count =
    CALCULATE (
        MAX ( 'Table'[Count] ),
        FILTER ( 'Table', 'Table'[id] = EARLIER ( 'Table'[id] ) )
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[response] ),
        FILTER (
            'Table',
            'Table'[id] = EARLIER ( 'Table'[id] )
                && 'Table'[Count] = _count
        )
    )

yingyinr_0-1677738678347.png

Best Regards

View solution in original post

11 REPLIES 11
BIswajit_Das
Impactful Individual
Impactful Individual

Actually i need the measure value in a column

Anonymous
Not applicable

Hi @BIswajit_Das ,

You can create a calculated column as below to replace the measure, please find the details in the attachment.

Column =
VAR _count =
    CALCULATE (
        MAX ( 'Table'[Count] ),
        FILTER ( 'Table', 'Table'[id] = EARLIER ( 'Table'[id] ) )
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[response] ),
        FILTER (
            'Table',
            'Table'[id] = EARLIER ( 'Table'[id] )
                && 'Table'[Count] = _count
        )
    )

yingyinr_0-1677738678347.png

Best Regards

Anonymous
Not applicable

I liked this solution 

I have this now

x  y  z

1  a  a

1  b  a

1  a  a

2  a  a

3  b  b

And i need to create a visual like

for a                                                            for b

2/3  (z-count/distintcount-x)                      1/3 

Is there any way to do this??

Anonymous
Not applicable

Hi @BIswajit_Das ,

I created a sample pbix file(see the attachment), please check if that is what you want.

1. Create a z field dimension table

Z = VALUES('Table'[z])

2. Create a measure as below

Measure = 
VAR _selvalue =
    SELECTEDVALUE ( 'Z'[z] )
VAR _countx =
    DISTINCTCOUNT ( 'Table'[x] )
VAR _countz =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[x] ),
        FILTER ( 'Table', 'Table'[z] = _selvalue )
    )
RETURN
    DIVIDE ( _countz, _countx, 0 )

yingyinr_0-1677824704690.png

If you have new problem or requirement, you can post a new case in the community. Then more people will see it and resolve it shortly.

Best Regards

actually my requirement is to set visuals like 2/3 and 0/3

I've posted this on new massage please check the below link

"https://community.powerbi.com/t5/Desktop/power-bi-visual/m-p/3109670/highlight/true#M1053860"

Anonymous
Not applicable

Hi @BIswajit_Das ,

I just reply you in the new case: power bi visual - Microsoft Power BI Community

Best Regards

Thanks it's really helpfull

Anonymous
Not applicable

Hi @BIswajit_Das ,

I created a sample pbix file(see the attachment), please check if that is what you want.

1. Create a calculated column as below to get the count of per response under per id

Count = 
CALCULATE (
    COUNT ( 'Table'[response] ),
    FILTER (
        'Table',
        'Table'[id] = EARLIER ( 'Table'[id] )
            && 'Table'[response] = EARLIER ( 'Table'[response] )
    )
)

yingyinr_0-1677638642801.png

2. Create a measure as below to get the response which have the max count

Maxcountbasedata = 
VAR _selid =
    SELECTEDVALUE ( 'Table'[id] )
VAR _count =
    CALCULATE (
        MAX ( 'Table'[Count] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[id] = _selid )
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[response] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[id] = _selid
                && 'Table'[Count] = _count
        )
    )

yingyinr_1-1677638752124.png

Best Regards

Thanks a lot It's really helpful

But i need the measure value in a column to use it on the shape map

Is there any way to so

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors