cancel
Showing results 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.

Anonymous
Not applicable

## Count and sum by creating groups/bins filtered on date

Hi ,

Below mentioned is a sample data. I need to create grouping / bin and show count of name and sum in each group based on date filter selected on any 1 particular date.

 Date Name Sum 01-01-2020 A 29 01-01-2020 A 20 01-01-2020 B 25 01-01-2020 C 9 01-01-2020 D 11 02-01-2020 A 30 02-01-2020 B 27 02-01-2020 C 4 02-01-2020 C 2 02-01-2020 D 2 02-01-2020 D 20 02-01-2020 E 27

This is the expected output for any 1 date that I can select using date filter.

 01-01-2020 Count Sum 0-20 2 20 21-40 1 25 41-60 1 49 61+ 0 0 02-01-2020 Count Sum 0-20 1 6 21-40 4 106 41-60 0 0 61+ 0 0

Any suggestion how to achieve this?

I tried using summarize function but was not able to do.

Regards,

Amit Darak

1 ACCEPTED SOLUTION
Community Support

Hi @Anonymous ,

You could try to achieve it through a matrix.

1.Create a Category table by entering data to put the range.

2.Create these measures.

``````Sum1 =
CALCULATE (
SUM ( 'Table'[Sum] ),
ALLEXCEPT ( 'Table', 'Table'[Date], 'Table'[Name] )
)``````
``````NewSum =
VAR _020 =
CALCULATE ( [Sum1], FILTER ( 'Table', [Sum1] >= 0 && [Sum1] <= 20 ) )
VAR _2140 =
CALCULATE ( [Sum1], FILTER ( 'Table', [Sum1] >= 21 && [Sum1] <= 40 ) )
VAR _4160 =
CALCULATE ( [Sum1], FILTER ( 'Table', [Sum1] >= 41 && [Sum1] <= 60 ) )
VAR _60 =
CALCULATE ( [Sum1], FILTER ( 'Table', [Sum1] >= 61 ) )
RETURN
SWITCH (
MAX ( 'Category'[Category] ),
"0-20", IF ( ISBLANK ( _020 ), 0, _020 ),
"21-40", IF ( ISBLANK ( _2140 ), 0, _2140 ),
"41-60", IF ( ISBLANK ( _4160 ), 0, _4160 ),
"61+", IF ( ISBLANK ( _60 ), 0, _60 )
)``````
``````Count =
VAR _020 =
CALCULATE (
DISTINCTCOUNT ( 'Table'[Name] ),
FILTER ( 'Table', [Sum1] >= 0 && [Sum1] <= 20 )
)
VAR _2140 =
CALCULATE (
DISTINCTCOUNT ( 'Table'[Name] ),
FILTER ( 'Table', [Sum1] >= 21 && [Sum1] <= 40 )
)
VAR _4160 =
CALCULATE (
DISTINCTCOUNT ( 'Table'[Name] ),
FILTER ( 'Table', [Sum1] >= 41 && [Sum1] <= 60 )
)
VAR _60 =
CALCULATE ( DISTINCTCOUNT ( 'Table'[Name] ), FILTER ( 'Table', [Sum1] >= 60 ) )
RETURN
SWITCH (
MAX ( 'Category'[Category] ),
"0-20", IF ( ISBLANK ( _020 ), 0, _020 ),
"21-40", IF ( ISBLANK ( _2140 ), 0, _2140 ),
"41-60", IF ( ISBLANK ( _4160 ), 0, _4160 ),
"61+", IF ( ISBLANK ( _60 ), 0, _60 )
)``````

3.Create a matrix as follows.

4. You can filter by date through the date slicer.

You can check more details from here.

Best Regards,

Stephen Tao

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

5 REPLIES 5
Community Support

Hi @Anonymous ,

You could try to achieve it through a matrix.

1.Create a Category table by entering data to put the range.

2.Create these measures.

``````Sum1 =
CALCULATE (
SUM ( 'Table'[Sum] ),
ALLEXCEPT ( 'Table', 'Table'[Date], 'Table'[Name] )
)``````
``````NewSum =
VAR _020 =
CALCULATE ( [Sum1], FILTER ( 'Table', [Sum1] >= 0 && [Sum1] <= 20 ) )
VAR _2140 =
CALCULATE ( [Sum1], FILTER ( 'Table', [Sum1] >= 21 && [Sum1] <= 40 ) )
VAR _4160 =
CALCULATE ( [Sum1], FILTER ( 'Table', [Sum1] >= 41 && [Sum1] <= 60 ) )
VAR _60 =
CALCULATE ( [Sum1], FILTER ( 'Table', [Sum1] >= 61 ) )
RETURN
SWITCH (
MAX ( 'Category'[Category] ),
"0-20", IF ( ISBLANK ( _020 ), 0, _020 ),
"21-40", IF ( ISBLANK ( _2140 ), 0, _2140 ),
"41-60", IF ( ISBLANK ( _4160 ), 0, _4160 ),
"61+", IF ( ISBLANK ( _60 ), 0, _60 )
)``````
``````Count =
VAR _020 =
CALCULATE (
DISTINCTCOUNT ( 'Table'[Name] ),
FILTER ( 'Table', [Sum1] >= 0 && [Sum1] <= 20 )
)
VAR _2140 =
CALCULATE (
DISTINCTCOUNT ( 'Table'[Name] ),
FILTER ( 'Table', [Sum1] >= 21 && [Sum1] <= 40 )
)
VAR _4160 =
CALCULATE (
DISTINCTCOUNT ( 'Table'[Name] ),
FILTER ( 'Table', [Sum1] >= 41 && [Sum1] <= 60 )
)
VAR _60 =
CALCULATE ( DISTINCTCOUNT ( 'Table'[Name] ), FILTER ( 'Table', [Sum1] >= 60 ) )
RETURN
SWITCH (
MAX ( 'Category'[Category] ),
"0-20", IF ( ISBLANK ( _020 ), 0, _020 ),
"21-40", IF ( ISBLANK ( _2140 ), 0, _2140 ),
"41-60", IF ( ISBLANK ( _4160 ), 0, _4160 ),
"61+", IF ( ISBLANK ( _60 ), 0, _60 )
)``````

3.Create a matrix as follows.

4. You can filter by date through the date slicer.

You can check more details from here.

Best Regards,

Stephen Tao

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

Super User

@Anonymous - Create a calculated column like this:

``````Column =
SWITCH(TRUE(),
[Sum]<=20,"0-20",
[Sum]>20 && [Sum]<=40,"21-40",
[Sum]>40 && [Sum]<=60,"41-60",
"61+"
)``````

Then you can use this column in a visual and use default aggregations.

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler  - It does not give the output as expected.

Super User

@Anonymous Can you be more specific?

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Super User

Announcements

#### 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

#### Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

#### Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors