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

GROUPBY with filter conditions on columns

Hello,

Is it possible to use GROUPBY with some sort of conditions on the columns?  Something along the lines of 

GROUPBY(
    'Employee Detail',
    'Employee Detail'[Cost Ctr],
    "Count of Primary", COUNTAX(CURRENTGROUP(), 'Employee Detail'[Employee Category] = "Primary Department"),
    "Count of Residual", COUNTAX(CURRENTGROUP(), 'Employee Detail'[Employee Category] = "Residual Employees")
    )

The first column (Primary Department) works but the 2nd column (Residual Employees) just repeats the same values as the 1st column.  I have maybe a dozen of these columns I want to add with conditions.  I know we cannot use CALCULATE with GROUPBY so maybe this is just the wrong function and I should stick with SUMMARIZE or SUMMARIZECOLUMNS instead?  What is best practice for grouping data like this with conditions?  Thanks!
 
-Scott
2 REPLIES 2
johnt75
Super User
Super User

I think you'd need to use ADDCOLUMNS ... SUMMARIZE, like

Summary Table =
ADDCOLUMNS (
    SUMMARIZE ( 'Employee Detail', 'Employee Detail'[Cost Ctr] ),
    "Count of Primary",
        CALCULATE (
            COUNTROWS ( 'Employee Detail' ),
            'Employee Detail'[Employee Category] = "Primary Department"
        ),
    "Count of Residual",
        CALCULATE (
            COUNTROWS ( 'Employee Detail' ),
            'Employee Detail'[Employee Category] = "Residual Employees"
        )
)
amitchandak
Super User
Super User

@Anonymous , I think you can do some calculations using Earlier

Earlier: https://youtu.be/CVW6YwvHHi8

 

If this does not help
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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!

December 2024

A Year in Review - December 2024

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