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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
JonSwed
Advocate II
Advocate II

Grouping by a column, using measure as value

Hi all,

I need some help.

My data looks like this:

JonSwed_0-1603733301425.png

I created the session2 column via a measure which counts the number of visitIdUnique_.

I want to get sessions2 per fullVisitorId (users) and then present sessions per user as a histogram. i.e. show the number of all users with 1 session, the number with 2 etc etc. Ideally, I want to create an additional column which is labelled buckets e.g. 1 session, 2 - 5 sessions, 6 - 10 sessions etc which I can then use in a chart.

Can anyone suggest a DAX formula/table combination I could use to do this? Many thanks for any help!

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

Hi, @JonSwed 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

b1.png

 

Test:

b2.png

 

You may create a measure as below.

CountSessions = 
var tab = 
SUMMARIZE(
    ALL('Table'),
    'Table'[FullVisitorId],
    "Count",
    DISTINCTCOUNT('Table'[VisitIdUnique])
)
var newtab = 
ADDCOLUMNS(
    Test,
    "Result",
    SWITCH(
        [Range],
        "1 session",
        COUNTROWS(
            FILTER(
                tab,
                [Count]=1
            )
        ),
        "2-5 sessions",
        COUNTROWS(
            FILTER(
                tab,
                [Count]>=2&&
                [Count]<=5
            )
        ),
        "6-10 sessions",
        COUNTROWS(
            FILTER(
                tab,
                [Count]>=6&&
                [Count]<=10
            )
        )
    )
)
return
SUMX(
    newtab,
    [Result]
)

 

Result:

b3.png

 

Best Regards

Allan

 

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

4 REPLIES 4
v-alq-msft
Community Support
Community Support

Hi, @JonSwed 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

b1.png

 

Test:

b2.png

 

You may create a measure as below.

CountSessions = 
var tab = 
SUMMARIZE(
    ALL('Table'),
    'Table'[FullVisitorId],
    "Count",
    DISTINCTCOUNT('Table'[VisitIdUnique])
)
var newtab = 
ADDCOLUMNS(
    Test,
    "Result",
    SWITCH(
        [Range],
        "1 session",
        COUNTROWS(
            FILTER(
                tab,
                [Count]=1
            )
        ),
        "2-5 sessions",
        COUNTROWS(
            FILTER(
                tab,
                [Count]>=2&&
                [Count]<=5
            )
        ),
        "6-10 sessions",
        COUNTROWS(
            FILTER(
                tab,
                [Count]>=6&&
                [Count]<=10
            )
        )
    )
)
return
SUMX(
    newtab,
    [Result]
)

 

Result:

b3.png

 

Best Regards

Allan

 

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

amitchandak
Super User
Super User

@JonSwed , if you want to create a column on a measure that is not possible. The workaround is independent table and segmentation/binning

https://www.youtube.com/watch?v=CuczXPj0N-k

 

or refer : https://www.daxpatterns.com/dynamic-segmentation/
https://www.daxpatterns.com/static-segmentation/
https://www.poweredsolutions.co/2020/01/11/dax-vs-power-query-static-segmentation-in-power-bi-dax-po...
https://radacad.com/grouping-and-binning-step-towards-better-data-visualization

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi again.

So, I'm getting somewhere but not quite there yet.

I used the dynamic segmention code that you linked to and is also described here.

This is allowing date selection but I'm struggling to get the metrics I want. Right now it's summing the number of sessions in each segment, whereas I want the count of fullVisitorId.

Here's my code:

 

VAR CustomersMaxPerYear = 
ADDCOLUMNS(
    VALUES ( GA_Hits_Mod_Help_UserTest[visitorIdTest] ),
    "MaxSales",
    CALCULATE(
        SUMX(  
            ALLSELECTED ( GA_Hits_Mod_Help_UserTest[hitDate_] ),
            CALCULATE( DISTINCTCOUNT(GA_Hits_Mod_Help_UserTest[visitIdUnique_]) )
        )
    )
)
VAR MinRange = MIN ( Segment[Min] )
VAR MaxRange = MAX ( Segment[Max] )
VAR CustomersInRange = 
FILTER (
    CustomersMaxPerYear,
    [MaxSales] > MinRange &&
    [MaxSales] <= MaxRange
)
RETURN
    CALCULATE ( DISTINCTCOUNT(GA_Hits_Mod_Help_UserTest[visitIdUnique_] ), CustomersInRange )

 


This returns the sum of sessions (visitIdUnique) in each segment, rather than the number of users in each session segment (users are visitorIdTest).
Here's an example of how the data looks:

JonSwed_0-1603877596208.png

 

And this is what my output is currently looking like:

JonSwed_1-1603877792773.png

Any pointers gratefully received. Thanks!












Thanks for that. Would it not be possible to create a new table where I group the fullVisitorId's by the sum of the sessions, based off this table?

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.