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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

AGGREGATION - How to filter on dates with a dynamic group by which doesnt have date in aggregation

Hello everyone, 

 

Dataset is below:

Location

dates

count

x

1/25/2019

1

x

3/11/2019

1

y

1/11/2019

1

y

1/12/2019

1

y

3/11/2019

1

a

1/12/2019

1

 

 

What we are looking for:

If the user selects date slicer with range:- 01/01/2019 - 02/28/2019

We want to aggregate records for that selection and group the counts like the process below:

 

Count grouped without date

Location

count

Custom calclation column

x

1

INT1

y

2

INT2

a

1

INT1

 

Final output that needs to showed in report/chart

Custom calculation columnCount of custom cal column

INT1

2

INT2

1

 

if the user selects date slicer with range:- 01/01/2019 - 03/11/2019

we want to aggregate records for that selection and group the counts like the process below:

Count grouped without date

Location

count

Customcalclation column

x

2

INT2

y

3

INT3

a

1

INT1

 

Final output that needs to showed in report/chart

 

Custom calculatuon column

Count of custom calculation column

INT1

1

INT2

1

INT3

1

 

 

We wanted to show the final output chart grouped dynamically with respect to the slicer values. Is this possible in power bi. What is the way to go about if it is possible. I looked into summarize and calculated tables  as well as the aggregation feature (group by in power query) but not been able to effectively move forward. Any ideas or if anyone has done this type of grouping/aggregation?

 

@Greg_Deckler reposted with more detail explanation

                               

1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @Anonymous ,

If I got it correctly, you can follow these steps to try:

1. Create a Date table related to Location date to use slicers to interact

2. Create first measure to get result of the first stage:

Custom measure =
"INT"
    & COUNTROWS (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Location] = SELECTEDVALUE ( 'Table'[Location] )
        )
    )

First stage resultFirst stage result

3. Create a reference table include 'INT1', 'INT2', 'INT3', just enter data manually

4. Create second measure to get result of the second stage:

Count of custom measure =
VAR _int =
    SELECTEDVALUE ( Test[INT] )
VAR tab =
    SUMMARIZE (
        DISTINCT ( 'Table'[Location] ),
        'Table'[Location],
        "Count", COUNTROWS (
            FILTER (
                ALLSELECTED ( 'Table' ),
                'Table'[Location] = EARLIER ( 'Table'[Location] )
            )
        )
    )
VAR newtab =
    ADDCOLUMNS (
        tab,
        "Result", "INT"
            & COUNTROWS (
                FILTER (
                    ALLSELECTED ( 'Table' ),
                    'Table'[Location] = EARLIER ( 'Table'[Location] )
                )
            )
    )
RETURN
    COUNTROWS ( FILTER ( newtab, [Result] = _int ) )

Second stage resultSecond stage result

Here is my sample file hope to help you, please try it: PBIX 

 

Best Regards,
Yingjie Li

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

6 REPLIES 6
v-yingjl
Community Support
Community Support

Hi @Anonymous ,

If I got it correctly, you can follow these steps to try:

1. Create a Date table related to Location date to use slicers to interact

2. Create first measure to get result of the first stage:

Custom measure =
"INT"
    & COUNTROWS (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Location] = SELECTEDVALUE ( 'Table'[Location] )
        )
    )

First stage resultFirst stage result

3. Create a reference table include 'INT1', 'INT2', 'INT3', just enter data manually

4. Create second measure to get result of the second stage:

Count of custom measure =
VAR _int =
    SELECTEDVALUE ( Test[INT] )
VAR tab =
    SUMMARIZE (
        DISTINCT ( 'Table'[Location] ),
        'Table'[Location],
        "Count", COUNTROWS (
            FILTER (
                ALLSELECTED ( 'Table' ),
                'Table'[Location] = EARLIER ( 'Table'[Location] )
            )
        )
    )
VAR newtab =
    ADDCOLUMNS (
        tab,
        "Result", "INT"
            & COUNTROWS (
                FILTER (
                    ALLSELECTED ( 'Table' ),
                    'Table'[Location] = EARLIER ( 'Table'[Location] )
                )
            )
    )
RETURN
    COUNTROWS ( FILTER ( newtab, [Result] = _int ) )

Second stage resultSecond stage result

Here is my sample file hope to help you, please try it: PBIX 

 

Best Regards,
Yingjie Li

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

Anonymous
Not applicable

@v-yingjl Is it possible to refine this logic based on another column thats not for a straight forward count for e.g. a column that has numbers? I realized countrows wont work if i want to base this logic on a different column called "impressions" which is not a count. Impressions have values from 0-1.

 

Dataset is below:

Location

dates

Impressions

x

1/25/2019

0

x

3/11/2019

0

y

1/11/2019

1

y

1/12/2019

1

y

3/11/2019

1

a

1/12/2019

1

 

 

What we are looking for:

If the user selects date slicer with range:- 01/01/2019 - 02/28/2019

We want to aggregate records for that selection and group the counts like the process below:

 

Count grouped without date

Location

count

Custom calclation column

y

2

INT2

a

1

INT1

 

Anonymous
Not applicable

Hi @v-yingjl This worked great, I have another requirement where now I have to aggregate the "Count of custom measure" ,  because I need to subtract these counts from another value

 

INT        |  Count of Custom Measure

INT 1    |   2

INT 2    |    1

 

Result:

Count of Customer Measure

3

 

How would you take the sum of all the INT 1 through INT 11 into one row/result instead of how we had it seperated it by rows?

 

 

Anonymous
Not applicable

As you can see, I tried to subtract INT0 with the custom measure we created to grab INT 1 -11 but because of the row context it keeps the subtraction each row when I only want INT0 to be one value which is the "INT0 based on single or multi select" - CountofCustomMeasure @v-yingjl 

 
Anonymous
Not applicable

This is exactly what we needed. Thank you, it works perfectly! @v-yingjl 

Greg_Deckler
Super User
Super User

Very difficult to tell. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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.