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
amuola
Helper II
Helper II

Counting the number of unique ID's/rows based on a criteria from one of the columns in the table

Hi,

 

Can someone explain how I can count the number of unique «Bookingnr» where the USERID has two different values in the “Transaction”?

e.g in this case the measure or a calculated column should return 1 (or something that indicate a hit for the function) for Bookingnumber 234 and 345 (since there is two different USERID for 1. Signature and 2. Signature), while the other two Bookingnumbers are 0/ False.

 

BookingnrTransactionUSERIDTimestamp

1231. SignatureAAA01.08.2018 00:00
1232. SignatureAAA02.08.2018 00:00
2341. SignatureAAA03.08.2018 00:00
2342. SignatureBBB04.08.2018 00:00
3451. SignatureAAA06.08.2018 00:00
3452. SignatureBBB07.08.2018 00:00
4561. SignatureBBB08.08.2018 00:00
4562. SignatureBBB09.08.2018 00:00

 

Appreciate any suggestions!

 

Regards

Amund

1 ACCEPTED SOLUTION

Hi @amuola,

 

Maybe you can try to use allselected function to replace all to enable filter effects on original tables.

Measure =
VAR BookingUser =
    GROUPBY (
        SUMMARIZE (
            FILTER (
                ALLSELECTED ( 'Table' ),
                [Transaction] IN { "1. Signature", "2. Signature" }
            ),
            [Bookingnr],
            [USERID]
        ),
        [Bookingnr],
        "NrOfUsers", COUNTAX ( CURRENTGROUP (), [USERID] )
    )
VAR OnlyMultiple =
    FILTER ( BookingUser, [NrOfUsers] > 1 )
RETURN
    COUNTROWS ( OnlyMultiple )

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

5 REPLIES 5
Stachu
Community Champion
Community Champion

try the code below, the logic is following
1) summarize bookings and users
2) group the summary and count nr of users per booking
3) filter only those where nr of users >1
4) count the outcome

Measure =
VAR BookingUser =
    GROUPBY (
        SUMMARIZE ( 'Table', 'Table'[Bookingnr], 'Table'[USERID] ),
        'Table'[Bookingnr],
        "NrOfUsers", COUNTAX ( CURRENTGROUP (), [USERID] )
    )
VAR OnlyMultiple =
    FILTER ( BookingUser, [NrOfUsers] > 1 )
RETURN
    COUNTROWS ( OnlyMultiple )

Cheers

Stachu



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Hi,

 

Thanks! However, I am not able to split the number down on e.g department, time, other possible filters – I assume using ALL it will not take into account the filters; in this example I have added Dep and by splitting the measure down on Dep it shows the same value for all Dep.

 

Skjermbilde.PNGSkjermbildeI.PNG

 

 

 

Any suggestions?

 

Regards

Amund

Hi @amuola,

 

Maybe you can try to use allselected function to replace all to enable filter effects on original tables.

Measure =
VAR BookingUser =
    GROUPBY (
        SUMMARIZE (
            FILTER (
                ALLSELECTED ( 'Table' ),
                [Transaction] IN { "1. Signature", "2. Signature" }
            ),
            [Bookingnr],
            [USERID]
        ),
        [Bookingnr],
        "NrOfUsers", COUNTAX ( CURRENTGROUP (), [USERID] )
    )
VAR OnlyMultiple =
    FILTER ( BookingUser, [NrOfUsers] > 1 )
RETURN
    COUNTROWS ( OnlyMultiple )

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi,

 

Thank you so much, this works on the data provided.

 

However, I forgot to include other activities within each booking nr which can be executed by different USERID’s. This make it a bit more complicated, or is it possible to modify the measure to take into account that the only Transactions it should check is “1. Signature” and “2. Signature”. I’m sorry that I didn’t include this in the first post.

 

BookingnrTransactionUSERIDTimestamp

123ActivityYAAA01.08.2018 00:00
1231. SignatureAAA02.08.2018 00:00
123Activity XCCC03.08.2018 00:00
1232. SignatureAAA04.08.2018 00:00
345ActivityYAAA06.08.2018 00:00
3451. SignatureBBB07.08.2018 00:00
345Activity XDDD08.08.2018 00:00
3452. SignatureBBB09.08.2018 00:00
789ActivityYAAA10.08.2018 00:00
7891. SignatureBBB11.08.2018 00:00
789Activity XAAA12.08.2018 00:00
7892. SignatureAAA13.08.2018 00:00

In this case only Booking nr 789 should return 1.

 

Again, appreciate any help!

 

Regards

Amund

Hi @amuola,

 

You can add filter to remove unmatched records before summarize, I modify Stachus's formula to add filter formula in it.

Measure =
VAR BookingUser =
    GROUPBY (
        SUMMARIZE (
            FILTER ( ALL ( 'Table' ), [Transaction] IN { "1. Signature", "2. Signature" } ),
            [Bookingnr],
            [USERID]
        ),
        [Bookingnr],
        "NrOfUsers", COUNTAX ( CURRENTGROUP (), [USERID] )
    )
VAR OnlyMultiple =
    FILTER ( BookingUser, [NrOfUsers] > 1 )
RETURN
    COUNTROWS ( OnlyMultiple )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.