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
BIswajit_Das
Resolver III
Resolver III

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
v-yiruan-msft
Community Support
Community Support

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

Community Support Team _ Rena
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

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

Community Support Team _ Rena
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

11 REPLIES 11
BIswajit_Das
Resolver III
Resolver III

Actually i need the measure value in a column

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

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

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??

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

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

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"

Hi @BIswajit_Das ,

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

Best Regards

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

Thanks it's really helpfull

v-yiruan-msft
Community Support
Community Support

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

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

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
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.