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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
BIswajit_Das
Solution Supplier
Solution Supplier

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
Solution Supplier
Solution Supplier

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.