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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Krisztian
Regular Visitor

Get distinct values and lookup count

 

Hi everyone,

I have the below scenario where the employees are listed with their current and next managers.

From this i would need to get the distinct values of the managers and then count the number of current and future employees belonging to them as below. Is there any way to do it with DAX functions. I already did the part for getting the unique values by creating a new table with UNION(SELECTCOLUMNS...), but not able to do the lookup count similar to the Excel COUNTIF function.

Thanks.

powerbi.png

 

2 ACCEPTED SOLUTIONS
SabineOussi
Skilled Sharer
Skilled Sharer

Hi @Krisztian

 

One way to do this is to unpivot columns Current Manger and Next Manager.

 

Go to Edit Queries, select these two columns, go to Transform tab and choose Unpivot Columns

Untitled.png

You table should now look like this

Capture.PNG

 

Hit Close and Apply for changes to take effect.

 

From the report page, select the matrix visual and distribute your fileds as below to get the desired view

Capture2.PNG

 

Make sure you are grouping the Employees by count.

You can always turn off the totals and change the field names.

 

Hope this helps!

View solution in original post

v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @Krisztian,

 

You can achieve your goal using DAX functions.

 

In your source table, add two calculated columns:

Count Current =
CALCULATE (
    COUNT ( 'lookUp Count'[Employee] ),
    ALLEXCEPT ( 'lookUp Count', 'lookUp Count'[Current Manager] )
)

Count Next =
CALCULATE (
    COUNT ( 'lookUp Count'[Employee] ),
    ALLEXCEPT ( 'lookUp Count', 'lookUp Count'[Next Manager] )
)

1.PNG

 

Then, create an auxiliary table:

Table =
UNION (
    SELECTCOLUMNS (
        'lookUp Count',
        "Employee", 'lookUp Count'[Employee],
        "Manager", 'lookUp Count'[Current Manager]
    ),
    SELECTCOLUMNS (
        'lookUp Count',
        "Employee", 'lookUp Count'[Employee],
        "Manager", 'lookUp Count'[Next Manager]
    )
)

Create a new table to dispaly distinct values of the managers and add two calculated columns to count the number of current and future employees.

Table1 = SUMMARIZE('Table','Table'[Manager])

Current =
LOOKUPVALUE (
    'lookUp Count'[Count Current],
    'lookUp Count'[Current Manager], 'Table 1'[Manager]
)

Next =
LOOKUPVALUE (
    'lookUp Count'[Count Next],
    'lookUp Count'[Next Manager], 'Table 1'[Manager]
)

2.PNG

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
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

9 REPLIES 9
Krisztian
Regular Visitor

Thanks a lot for your assistance!

v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @Krisztian,

 

You can achieve your goal using DAX functions.

 

In your source table, add two calculated columns:

Count Current =
CALCULATE (
    COUNT ( 'lookUp Count'[Employee] ),
    ALLEXCEPT ( 'lookUp Count', 'lookUp Count'[Current Manager] )
)

Count Next =
CALCULATE (
    COUNT ( 'lookUp Count'[Employee] ),
    ALLEXCEPT ( 'lookUp Count', 'lookUp Count'[Next Manager] )
)

1.PNG

 

Then, create an auxiliary table:

Table =
UNION (
    SELECTCOLUMNS (
        'lookUp Count',
        "Employee", 'lookUp Count'[Employee],
        "Manager", 'lookUp Count'[Current Manager]
    ),
    SELECTCOLUMNS (
        'lookUp Count',
        "Employee", 'lookUp Count'[Employee],
        "Manager", 'lookUp Count'[Next Manager]
    )
)

Create a new table to dispaly distinct values of the managers and add two calculated columns to count the number of current and future employees.

Table1 = SUMMARIZE('Table','Table'[Manager])

Current =
LOOKUPVALUE (
    'lookUp Count'[Count Current],
    'lookUp Count'[Current Manager], 'Table 1'[Manager]
)

Next =
LOOKUPVALUE (
    'lookUp Count'[Count Next],
    'lookUp Count'[Next Manager], 'Table 1'[Manager]
)

2.PNG

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
SabineOussi
Skilled Sharer
Skilled Sharer

Hi @Krisztian

 

One way to do this is to unpivot columns Current Manger and Next Manager.

 

Go to Edit Queries, select these two columns, go to Transform tab and choose Unpivot Columns

Untitled.png

You table should now look like this

Capture.PNG

 

Hit Close and Apply for changes to take effect.

 

From the report page, select the matrix visual and distribute your fileds as below to get the desired view

Capture2.PNG

 

Make sure you are grouping the Employees by count.

You can always turn off the totals and change the field names.

 

Hope this helps!

Hi, but how do you think is it possible to put pivot on pivot, I mean if we have XX-4, XY-4, ZX -5 and put these figures on graph on x-axis and on y - axis count of current managers or next managers, like I have in the photo?Capture.PNG

Can you please explain what the bars and line are?

Are the bars the count of employees by current manager and the line the count of employees by next managers?

 

So you want something like this?

Capture.PNG

Will try to exlain you in different way, step by step!

First of all, I have some data:

Order No.Product
5754305x
5754305y
5754305y
5754306yy
5754306x
5754307z
5754307y
5754307z
5754307x
5754307yy
5754308x
5754308y
5754308y

 

I am preparing in excel pivot and get such data:

OrderCount of Product
57543053
57543062
57543075
57543083
Grand Total

13

 

But my goal is to make in POWER BI count of product on x-axis and count of orders on y-asis, like this:

Capture.PNG

So it means that I have 1 order with 2 items in it, 2 orders with 3 items and 1 order with 5 items

So I really want to exclude the step of making a pivot in excel, but from this data source at once make a graph like I already mentioned. Hope You can help me!:)

Vvelarde
Community Champion
Community Champion

@tomijs

 

in Edit Query to can Transform to make a Group By

 

GroupBy.png

 

The result is:

 

GroupBy2.png

 

Finally in a Table visual:

 

GroupBy3.png




Lima - Peru

Agree with @Vvelarde

That's a different scenario now.

Hi,

 

But, for example, if I need these figures that were counted: XX - 4, XY - 4 , ZX - 5 to put in graph with figures on x-axis count of empleyees. How do you think, is it possible to put pivot on pivot?

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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