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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
JaySharma
Frequent Visitor

Dynamic Group By Table.

I need to create a dynamic table grouped/binned dynamically with user inputs (Slicers). The Data looks like this. 

IndexNet WorthCitizen
210000000
471000001
759000000
918000000
1095000001
1115000000
1357000000
1464000000
1599000001
1783000000
1878000000
1922000000
2010000000

I have tried calculated tables, and creating various measures, but being a DAX beginner, I'm unable to solve the problem. 
This is how my input is taken. 

JaySharma_0-1690958715124.png


The expected output is somewhat like this.

BinsAverage NWCount IndexCount Citizen
0-1938062   
1938062-6623377   
6623377-10000000   


The bins need to be created on the basis of the slicer values. 

It'd be great if someone guides me towards the right approach. 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @JaySharma ,

You can follow the steps below to get it, please check if that is what you want.

1. Create a dimension table using "Enter data" method

vyiruanmsft_1-1691119983844.png

2. Create the measures as below

 

Bins = 
    SWITCH (
        SELECTEDVALUE ( 'Bins'[Index] ),
        0, "0-" & [NW-low],
        1,
            [NW-low] & "-" & [NW-high],
        2,
            [NW-high] & "-" & 10000000
    )
Average NW = 
VAR _len1 =
    SEARCH ( "-", [Bins], 1, 0 )
VAR _minnw =
    VALUE ( MID ( [Bins], 1, _len1 - 1 ) )
VAR _maxnw =
    VALUE ( MID ( [Bins], _len1 + 1, LEN ( [Bins] ) - _len1 ) )
RETURN
    CALCULATE (
        AVERAGE ( 'Table'[Net Worth] ),
        FILTER ( 'Table', 'Table'[Net Worth] >= _minnw && 'Table'[Net Worth] <= _maxnw )
    )
Count Index = 
VAR _len1 =
    SEARCH ( "-", [Bins], 1, 0 )
VAR _minnw =
    VALUE ( MID ( [Bins], 1, _len1 - 1 ) )
VAR _maxnw =
    VALUE ( MID ( [Bins], _len1 + 1, LEN ( [Bins] ) - _len1 ) )
RETURN
    CALCULATE (
        COUNT ( 'Table'[Index] ),
        FILTER ( 'Table', 'Table'[Net Worth] >= _minnw && 'Table'[Net Worth] <= _maxnw )
    )
Count Citizen = 
VAR _len1 =
    SEARCH ( "-", [Bins], 1, 0 )
VAR _minnw =
    VALUE ( MID ( [Bins], 1, _len1 - 1 ) )
VAR _maxnw =
    VALUE ( MID ( [Bins], _len1 + 1, LEN ( [Bins] ) - _len1 ) )
RETURN
    CALCULATE (
        SUM ( 'Table'[Citizen] ),
        FILTER ( 'Table', 'Table'[Net Worth] >= _minnw && 'Table'[Net Worth] <= _maxnw )
    )

 

3. Create a table visual which need to include the field [Index] of dimension table 'Bins'

vyiruanmsft_0-1691119656094.png

Best Regards

View solution in original post

6 REPLIES 6
JaySharma
Frequent Visitor

Hello @Anonymous , 
I added the 'Bins'[Index] in the visual before, and I believe text wrap has any effect on the values of 'Average NW', and the counts. 
Here's the screenshot: 

JaySharma_0-1691131967427.png

 

 

The expected output is in the original post, I was able to achieve it with a makeshift solution by creating measures for every Bin but I wanted all the values to be in a single table/visual. Here's the screenshot of something close to what I'm trying to achieve: 

JaySharma_1-1691132468972.png

 

Also, it'd be great if you could share your pbix file as for some reason, my tables aren't populating even when I did exactly what you did. 

Thanks & regards

Jay Sharma

 

Anonymous
Not applicable

Hi @JaySharma ,

I attached the pbix file here, please find the details in it. Please update the max value of parameter 'Slicer 1' and 'Slicer 2' as 10000000 after you got the pbix file. I update their value as 1000 in my attached pbix file due to the community upload file size limitation.

vyiruanmsft_0-1691133583160.png

If it is convenient, you can also share your pbix file(exclude sensitive info) with me. Later I can check why the avg and count measures not return the values....

How to upload PBI in Community

Best Regards

Hey @Anonymous ,

The initial solution you provided, worked. The issue was with the data model, while trying something out previously, I connected the slicer table with the data table and that's why it wasn't populating. I apologize for the fruitless inconvenience I caused. 

Once I removed the useless relations between the tables, everything worked like a charm! 

Thanks a ton for helping me out !!!

 

Regards
Jay Sharma

Anonymous
Not applicable

Hi @JaySharma ,

You can follow the steps below to get it, please check if that is what you want.

1. Create a dimension table using "Enter data" method

vyiruanmsft_1-1691119983844.png

2. Create the measures as below

 

Bins = 
    SWITCH (
        SELECTEDVALUE ( 'Bins'[Index] ),
        0, "0-" & [NW-low],
        1,
            [NW-low] & "-" & [NW-high],
        2,
            [NW-high] & "-" & 10000000
    )
Average NW = 
VAR _len1 =
    SEARCH ( "-", [Bins], 1, 0 )
VAR _minnw =
    VALUE ( MID ( [Bins], 1, _len1 - 1 ) )
VAR _maxnw =
    VALUE ( MID ( [Bins], _len1 + 1, LEN ( [Bins] ) - _len1 ) )
RETURN
    CALCULATE (
        AVERAGE ( 'Table'[Net Worth] ),
        FILTER ( 'Table', 'Table'[Net Worth] >= _minnw && 'Table'[Net Worth] <= _maxnw )
    )
Count Index = 
VAR _len1 =
    SEARCH ( "-", [Bins], 1, 0 )
VAR _minnw =
    VALUE ( MID ( [Bins], 1, _len1 - 1 ) )
VAR _maxnw =
    VALUE ( MID ( [Bins], _len1 + 1, LEN ( [Bins] ) - _len1 ) )
RETURN
    CALCULATE (
        COUNT ( 'Table'[Index] ),
        FILTER ( 'Table', 'Table'[Net Worth] >= _minnw && 'Table'[Net Worth] <= _maxnw )
    )
Count Citizen = 
VAR _len1 =
    SEARCH ( "-", [Bins], 1, 0 )
VAR _minnw =
    VALUE ( MID ( [Bins], 1, _len1 - 1 ) )
VAR _maxnw =
    VALUE ( MID ( [Bins], _len1 + 1, LEN ( [Bins] ) - _len1 ) )
RETURN
    CALCULATE (
        SUM ( 'Table'[Citizen] ),
        FILTER ( 'Table', 'Table'[Net Worth] >= _minnw && 'Table'[Net Worth] <= _maxnw )
    )

 

3. Create a table visual which need to include the field [Index] of dimension table 'Bins'

vyiruanmsft_0-1691119656094.png

Best Regards

Hey @Anonymous ,
Thank you for responding!

 

I did exactly what you mentioned, but the average and count fields aren't getting populated. 

JaySharma_0-1691128918725.png

 

To check where is it broken, I Replaced the return variable so that I can verify every variable is returning the right value. 

 

[Bins] seem fine.

JaySharma_2-1691129457901.png

So does the _len1

JaySharma_3-1691129726615.png

_minnw and _maxnw are correct too. 

JaySharma_4-1691129804023.pngJaySharma_5-1691129831113.png

This is where it breaks down: 

JaySharma_6-1691130054361.png

 

I hope we find a solution to this problem. 

 

Regards, 

Jay Sharma

 

Anonymous
Not applicable

Hi @JaySharma ,

Actually, I also add the field [Index] of the table 'Bins' in the table visual. But it was "hidden" by toggling off the option "Text wrap" of Values & Column headers and reducing the size of field [Index].

vyiruanmsft_0-1691130626048.png

Toggle off the option "Text wrap"Toggle off the option "Text wrap"

vyiruanmsft_2-1691130910505.png

Base on your provided data, what's your expected result? Could you please explain more details with the specific examples or screenshots? It would be helpful to find out the solution. Thank you.

Best Regards

Helpful resources

Announcements
May PBI 25 Carousel

Power BI Monthly Update - May 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

May 2025 Monthly Update

Fabric Community Update - May 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors