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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
hong88
Regular Visitor

Need help with DAX to create a card identifying Count of employeeID with no sales

Hi there,

 

I am new to this community, but I have read through a number of solutions and it was of great help. 

 

I currently have a problem figuring out how to create a card to identify the count of employees with 0 sales for both years and have worked in the company for more than 1 year.

 

I created a little mock table with the relevant details.

 

I really hope someone can help me, I am truly at a loss at the moment. 

Capture2.PNG 

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

Hi @hong88 

 

Please try this:

Here is the sample data:

'Table':

vzhengdxumsft_0-1725327024547.png

Then add a measure:

MEASURE =
VAR _vtable =
    FILTER (
        ADDCOLUMNS (
            'Table',
            "_Sumsales",
                CALCULATE (
                    SUM ( 'Table'[Sales Amount] ),
                    'Table'[EmployeeID] = EARLIER ( 'Table'[EmployeeID] )
                ),
            "_MaxTenure",
                CALCULATE (
                    MAX ( 'Table'[Tenure] ),
                    'Table'[EmployeeID] = EARLIER ( 'Table'[EmployeeID] )
                )
        ),
        [_MaxTenure] > 1
            && [_Sumsales] = 0
    )
RETURN
    COUNTROWS ( SUMMARIZE ( _vtable, 'Table'[EmployeeID] ) )

The variable [_vtable] returns:

vzhengdxumsft_1-1725327238741.png

So the result is as follow:

vzhengdxumsft_2-1725327265530.png

 

 

Best Regards

Zhengdong Xu
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

7 REPLIES 7
v-zhengdxu-msft
Community Support
Community Support

Hi @hong88 

 

Please try this:

Here is the sample data:

'Table':

vzhengdxumsft_0-1725327024547.png

Then add a measure:

MEASURE =
VAR _vtable =
    FILTER (
        ADDCOLUMNS (
            'Table',
            "_Sumsales",
                CALCULATE (
                    SUM ( 'Table'[Sales Amount] ),
                    'Table'[EmployeeID] = EARLIER ( 'Table'[EmployeeID] )
                ),
            "_MaxTenure",
                CALCULATE (
                    MAX ( 'Table'[Tenure] ),
                    'Table'[EmployeeID] = EARLIER ( 'Table'[EmployeeID] )
                )
        ),
        [_MaxTenure] > 1
            && [_Sumsales] = 0
    )
RETURN
    COUNTROWS ( SUMMARIZE ( _vtable, 'Table'[EmployeeID] ) )

The variable [_vtable] returns:

vzhengdxumsft_1-1725327238741.png

So the result is as follow:

vzhengdxumsft_2-1725327265530.png

 

 

Best Regards

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

PabloVallejo12
Frequent Visitor

Did you try to use the summarize function, with a filter in sales amount = 0 ?

I tried, but im a bit confused because the IDs appear twice and have to be filtered together, meaning if ID 2233 has 0 sales in 2022, but has 9915 in sales in 2023, it should not appear as an ID without sales for both years. 

 

The only ones that should be counted are IDs with both years = 0 and tenure > 1. 

 

I tried using CALCULATE(countrows(table),
filter(values(table[SalesAmount]),
Calculate(SUM(table[SalesAmount])=0)

Basically what I got back are just the rows with 0, im not sure how to futher filter based on same employeeID for 2022 and 2023 = 0 and tenure >1. 

Maybe you can create a measure for each sales year, and use it for filter

edit: I think ive partially solved it, still cant figure out how to group it by ID and filter it if both years = 0. But I've decided to filter twice by year and by tenure > 0. 

 

Thanks for your help, ur ideas helped me think of alternative ways to analyse. But if anyone still knows the DAX for the original problem, I would be really interested to find out too 😊

hello @hong88 

 

please check if this accomodate your need.

 

for count employee with zero sales in both year, create a new measure with following DAX.

Count =
var _Sales =
SUMMARIZE(
    FILTER(
        SUMMARIZE(
            'Table',
            'Table'[EmployeeID],
            "Sum",
            SUM('Table'[Sales Amount])
        ),
        [Sum]=0
    ),
    'Table'[EmployeeID]
)
Return
COUNTROWS(_Sales)
Irwan_0-1725330828540.png

 

if you want to do with SUMMARIZE, then just copy that _Sales DAX into new table.

Summarize = 
SUMMARIZE(
    FILTER(
        SUMMARIZE(
            'Table',
            'Table'[EmployeeID],
            "Sum",
            SUM('Table'[Sales Amount])
        ),
        [Sum]=0
    ),
    'Table'[EmployeeID]
)
Irwan_1-1725330902980.png

 

if you need another filter for Tenure>0, then just add that line inside the FILTER.

Hope this will help.

Thank you.

Thanks everyone for your suggestions! couldnt have been able to do it without ur help. 😊

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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