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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
tcheong
Frequent Visitor

Group by different column based on slicer value

Hello, please refer to this pbix for this question.

 

Background:

I have the following data in the 'Products' table:

IdCreatedDateGradeModifiedDateNewGrade
1

10 Nov 2020

A10 Nov 2020B
212 Nov 2020A16 Nov 2020C
315 Nov 2020B19 Nov 2020C
422 Nov 2020B30 Nov 2020A

 

The values of [Grade] and [NewGrade] are always either "A", "B", or "C". 

 

There is also a 'DateDim' table with a one-to-many relationship to 'Products'.[CreatedDate]. A date range slicer is created for 'DateDim'.[Date]:

CreatedDate Slicer.png

 

The Problem:

I want to know how many products are in each grade within the selected date range. Howeverif the max date in the date range slicer is >= [ModifiedDate], it should be grouped by the value in [NewGrade] instead of [Grade].


For example, the expected result for a date range between 10/11/2020 and 17/11/2020 should be:

GradeCount
B2
C

1


Expected results for a date range between 10/11/2020 and 22/11/2020 should be:

GradeCount
B2
C

2

 

How can I achieve these results?

1 ACCEPTED SOLUTION
tcheong
Frequent Visitor

Hello, I managed to achieve what I needed by creating a measure for each grade like so:

_ProductCount_GradeA = 
VAR slicerMaxDate = MAX(DateDim[Date])

RETURN
    CALCULATE(
        COUNT(Products[Id]),
        FILTER(
            ALL(Products[ModifiedDate], Products[Grade], Products[NewGrade]),
            IF(Products[ModifiedDate] <= slicerMaxDate, [NewGrade], [Grade]) = "A"
        )
    ) + 0

 

You may refer to this PBIX for my solution.

 

Thanks to everyone who took the time to consider my question. Have a nice day!

View solution in original post

1 REPLY 1
tcheong
Frequent Visitor

Hello, I managed to achieve what I needed by creating a measure for each grade like so:

_ProductCount_GradeA = 
VAR slicerMaxDate = MAX(DateDim[Date])

RETURN
    CALCULATE(
        COUNT(Products[Id]),
        FILTER(
            ALL(Products[ModifiedDate], Products[Grade], Products[NewGrade]),
            IF(Products[ModifiedDate] <= slicerMaxDate, [NewGrade], [Grade]) = "A"
        )
    ) + 0

 

You may refer to this PBIX for my solution.

 

Thanks to everyone who took the time to consider my question. Have a nice day!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors