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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Syndicate_Admin
Administrator
Administrator

Segmentation from the same column

Best regards!
I have a problem, I hope you can explain me well and you can help me...
In a table I have a list of people (unique ID code), and a column that identifies travel and travel by codes in the same column.

usercodeCodegroup
user1barcoVehicle
user1airplaneVehicle
user1Madridcity
user2carVehicle
user2texascity
user3airplaneVehicle
user3Madridcity
user3Germanycity


then, I can count the users who have traveled by car, boat, plane, madrid, texas, but I need:
-segment the users who traveled in which vehicle, to which cities they traveled, that is, count "plane" and those users who traveled by plane to which cities they traveled.
-failing that of the city of Madrid how many traveled by boat and how many by plane.

as the data is in the same column because I can not filter them either with IF, or doing SWITCH
mesure boat =

CALCULATE(
COUNT(usercode] record),
registrationtray[code] = "boat"
recordtray[group] = "city"
)
the idea of this is then to make a graph where you put the number of trips per boat and the cities with their respective amount ...

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @Syndicate_Admin ,

According to your description, heres my solution.

For example calculating the count of users to Madrid by boat:

1.Create a measure to check the user to Madrid by boat.

 

Flag =
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        ALLEXCEPT ( 'Table', 'Table'[User code] ),
        [Code] = "boat"
            || [Code] = "Madrid"
    )
)

 

vkalyjmsft_0-1639132525585.png

2.Create another measure to count the user to Madrid by boat.

UserCount to Madrid by boat = CALCULATE(DISTINCTCOUNT('Table'[User code]),FILTER('Table',[Flag]=2))

vkalyjmsft_1-1639132525586.png

 

I attach my sample below for reference.

Best Regards,
Community Support Team _ kalyj

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

2 REPLIES 2
v-yanjiang-msft
Community Support
Community Support

Hi @Syndicate_Admin ,

According to your description, heres my solution.

For example calculating the count of users to Madrid by boat:

1.Create a measure to check the user to Madrid by boat.

 

Flag =
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        ALLEXCEPT ( 'Table', 'Table'[User code] ),
        [Code] = "boat"
            || [Code] = "Madrid"
    )
)

 

vkalyjmsft_0-1639132525585.png

2.Create another measure to count the user to Madrid by boat.

UserCount to Madrid by boat = CALCULATE(DISTINCTCOUNT('Table'[User code]),FILTER('Table',[Flag]=2))

vkalyjmsft_1-1639132525586.png

 

I attach my sample below for reference.

Best Regards,
Community Support Team _ kalyj

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

lbendlin
Super User
Super User

Your data is not in a usable format. Transfom it like this

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKi1OLTJU0lFKSixKzgfSYakZmck5qUqxOgi5xMyigpzEvFQc0r6JKUWZKUBGcmZJJVzGCCSQWIRFD0imJLUisRhdizF+u4xx2gWScU8tyk3Mq4RLxQIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [usercode = _t, Code = _t, group = _t]),
    #"Filter Vehicle" = Table.SelectRows(Source, each ([group] = "Vehicle")),
    #"Filter City" = Table.SelectRows(Source, each ([group] = "city")),
    #"Merged Queries" = Table.NestedJoin(#"Filter Vehicle", {"usercode"}, #"Filter City", {"usercode"}, "Table (2)", JoinKind.FullOuter),
    #"Renamed Columns" = Table.RenameColumns(#"Merged Queries",{{"Code", "Vehicle"}}),
    #"Expanded Table (2)" = Table.ExpandTableColumn(#"Renamed Columns", "Table (2)", {"Code"}, {"Code"}),
    #"Renamed Columns1" = Table.RenameColumns(#"Expanded Table (2)",{{"Code", "City"}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Renamed Columns1",{"usercode", "Vehicle", "City"})
in
    #"Removed Other Columns"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

 

Note: Germany is not a city.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.