Reply
avatar user
Anonymous
Not applicable
Partially syndicated - Outbound

Dynamic Grouping of Data in Visual Columns using Age(Values on X Axis) Slicer

Hello All Colleagues,

 

I want to group data(should come on Y Axis) in columns based on Age division(Age should come on X Axis) such that I need to select Maximum and Minimum Age based on What-if slicer values selection.

 

What approach do I need to follow??

 

Can someone give a quick solution to this. It will be much helpful

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

Syndicated - Outbound

Hi, @Anonymous 

 

Solution1:

I created a sample with the following data:

vangzhengmsft_0-1630656252421.png

Create 2 measures to determine the maximum and minimum values. It acts as a slicer

 

_min = 60

_max = 120

 

Create another measure to group ages.

 

Group = 
var _age=MAX('Table'[Age])
var _if=
    SWITCH(TRUE(),
    _age<[_min],"<"&[_min],
    _age>[_max],">"&[_max],
    [_min]&"~"&[_max])
return IF(ISFILTERED('Table'[Name]),_if)

 

Then, create a calculated table to get the grouped fields.

 

T = ADDCOLUMNS('Table',"Group",[Group])

 

Finally, create a measure to count users.

Model:

vangzhengmsft_1-1630656318544.png

result:

vangzhengmsft_2-1630656555500.png

 

Edit:

Solution2:

1. Create 2 whatif parameters to control the maximum and minimum values.

 

2. Create a grouping table, which contains three groups, namely <,<>,>.

vangzhengmsft_1-1631792959568.png

3. Then create a measure to calculate the count of names in the group.

R_Count = 
var _swith=
SWITCH(
    MAX('_Range'[Range]),
    "<",CALCULATE(COUNT('Table'[Name]),FILTER(ALL('Table'),'Table'[Age]<[_MINage Value])),
    ">",CALCULATE(COUNT('Table'[Name]),FILTER(ALL('Table'),'Table'[Age]>[_MAXage Value])),
    CALCULATE(COUNT('Table'[Name]),FILTER(ALL('Table'),'Table'[Age]<=[_MAXage Value]&&'Table'[Age]>=[_MINage Value])))
return IF(HASONEVALUE('_Range'[Range]),_swith,COUNT('Table'[Name]))

Finally, a bar graph is created with the groups and measures of the grouping table.

vangzhengmsft_2-1631793019251.png

 

Please refer to the attachment below for details. Hope this helps.

 

 

Best Regards,
Community Support Team _ Zeon Zheng


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

3 REPLIES 3
v-angzheng-msft
Community Support
Community Support

Syndicated - Outbound

Hi, @Anonymous 

 

Solution1:

I created a sample with the following data:

vangzhengmsft_0-1630656252421.png

Create 2 measures to determine the maximum and minimum values. It acts as a slicer

 

_min = 60

_max = 120

 

Create another measure to group ages.

 

Group = 
var _age=MAX('Table'[Age])
var _if=
    SWITCH(TRUE(),
    _age<[_min],"<"&[_min],
    _age>[_max],">"&[_max],
    [_min]&"~"&[_max])
return IF(ISFILTERED('Table'[Name]),_if)

 

Then, create a calculated table to get the grouped fields.

 

T = ADDCOLUMNS('Table',"Group",[Group])

 

Finally, create a measure to count users.

Model:

vangzhengmsft_1-1630656318544.png

result:

vangzhengmsft_2-1630656555500.png

 

Edit:

Solution2:

1. Create 2 whatif parameters to control the maximum and minimum values.

 

2. Create a grouping table, which contains three groups, namely <,<>,>.

vangzhengmsft_1-1631792959568.png

3. Then create a measure to calculate the count of names in the group.

R_Count = 
var _swith=
SWITCH(
    MAX('_Range'[Range]),
    "<",CALCULATE(COUNT('Table'[Name]),FILTER(ALL('Table'),'Table'[Age]<[_MINage Value])),
    ">",CALCULATE(COUNT('Table'[Name]),FILTER(ALL('Table'),'Table'[Age]>[_MAXage Value])),
    CALCULATE(COUNT('Table'[Name]),FILTER(ALL('Table'),'Table'[Age]<=[_MAXage Value]&&'Table'[Age]>=[_MINage Value])))
return IF(HASONEVALUE('_Range'[Range]),_swith,COUNT('Table'[Name]))

Finally, a bar graph is created with the groups and measures of the grouping table.

vangzhengmsft_2-1631793019251.png

 

Please refer to the attachment below for details. Hope this helps.

 

 

Best Regards,
Community Support Team _ Zeon Zheng


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

Fowmy
Super User
Super User

Syndicated - Outbound

@Anonymous 

Not clear enough but as I read your question, you can add Parameter on the report and modify your measure to within the Min and Max values selected in the Paramter.

You can find many articles and videos on google




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

avatar user
Anonymous
Not applicable

Syndicated - Outbound

It is like the screenshot below, such that when I select limit1 as 60 and limit2 as 120, so the bar graph will show like 1st bar should be '<60', 2nd bar should be between '60 to 120', 3rd bar should be 'more than 120'.

sbnst21_0-1630479965651.png

 

avatar user

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)